-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
92 lines (69 loc) · 1.99 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"encoding/json"
"github.com/pitw/doc-parser-proffix/doc"
"github.com/pitw/doc-parser-proffix/generator"
"github.com/pitw/doc-parser-proffix/model"
"github.com/pitw/doc-parser-proffix/table"
"io/ioutil"
"log"
"strconv"
)
var basePath = "_result/json_base/"
func main() {
//Hmm...
log.Println("Do ut des")
//Build base model / parse the tricky tables from PROFFIX in the hope they do a lot of copy & paste...
createBaseJson()
//Build our models from base model
createModels()
}
func createModels() {
//Create Models for Golang
err := generator.CreateGoStruct(basePath)
if err != nil {
log.Printf("Error on create Go struct: %v", err)
}
//Create CSV
err = generator.CreateCSV(basePath)
if err != nil {
log.Printf("Error on create CSV: %v", err)
}
}
func createBaseJson() {
// Object with all entities
allDocs := doc.CreateDocsAll()
//Collect links
doclinks := doc.GetDocLinks()
for _, y := range doclinks {
//Check if starts with int -> Release -> we don't need em
if _, err := strconv.Atoi(y.Name[:1]); err != nil {
mod := table.TableToStrings(y.Link)
//doc := table.TableToStrings("https://www.proffix.net/Portals/0/content/REST%20API/export/lohnbewegung.html")
docsJson, err := json.MarshalIndent(mod, "", " ")
if err != nil {
log.Fatal("Cannot encode to JSON ", err)
}
//Check if it makes sense to parse...
if len(mod.Fields) > 0 {
err = ioutil.WriteFile(basePath+y.Name+".json", docsJson, 0644)
if err != nil {
log.Fatal("Cannot write to File ", err)
}
// Add entity to object
allDocs.Entities = append(allDocs.Entities, model.DocLink{
Name: y.Name,
Link: y.Link,
Doc: mod,
})
}
}
}
// Serialize object with all entities
allDocsJson, err := json.MarshalIndent(allDocs, "", " ")
// Write JSON aof all entities to file "_AllEntities.json"
err = ioutil.WriteFile(basePath+"_AllEntities.json", allDocsJson, 0644)
if err != nil {
log.Fatal("Cannot write to File ", err)
}
}