-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.go
68 lines (57 loc) · 1.67 KB
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/360EntSecGroup-Skylar/excelize/v2"
"github.com/urfave/cli/v2"
)
type ToolData struct {
// timestamp string
Name string `json:"name"`
Description string `json:"description"`
Tags []string `json:"tags"`
OperatingSystems []string `json:"operating_systems"`
License string `json:"license"`
Availability []string `json:"availability"`
GithubURL string `json:"github_url"`
URL string `json:"url"`
}
const (
sheetName = "Output"
)
func convertXLSXToJSON(c *cli.Context) error {
inputXLSXFilePath := c.String("input")
// outputJSONFilePath := c.String("output")
f, err := excelize.OpenFile(inputXLSXFilePath)
if err != nil {
log.Fatal(err)
}
rows, err := f.GetRows(sheetName)
//currently doing for all rows, will handle this in future to only do recent or latest
for _, row := range rows {
var tool ToolData
tool.Name = row[1]
tool.Description = row[2]
tool.Tags = stringTrimSplit(row[3])
tool.OperatingSystems = stringTrimSplit(row[4])
tool.License = row[5]
tool.Availability = stringTrimSplit(row[6])
tool.GithubURL = row[7]
tool.URL = row[8]
// currently hardcoded the tools folder
// create tools directory before (will handle this in future)
outputJSONFilePath := "tools/" + safeCleanName(row[1]) + ".json"
jsonData, err := json.MarshalIndent(tool, "", " ")
if err != nil {
log.Println(err)
}
err = ioutil.WriteFile(outputJSONFilePath, jsonData, 0644)
if err != nil {
log.Println(err)
}
fmt.Println("Successfully saved the output to:", outputJSONFilePath)
}
return nil
}