This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
149 lines (120 loc) · 3.57 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/gosimple/slug"
)
type Place struct {
ID string `json:"id"`
Name string `json:"name"`
Deaths int `json:"deaths"`
Confirmed int `json:"confirmed"`
Recovered int `json:"recovered"`
LastUpdate string `json:"last_update"`
Timeseries []TimeseriesData `json:"ts,omitempty"`
}
type World struct {
Place
countryMap map[string]Country
Countries []Country `json:"countries,omitempty"`
}
type Country struct {
Place
provinceMap map[string]Province
Provinces []Province `json:"provinces,omitempty"`
}
type Province struct {
countryID string
Lat float64
Lng float64
Place
}
func main() {
recordsParsed := GetRecords()
world := Merge(recordsParsed)
os.Mkdir("world", os.ModePerm)
for _, country := range world.Countries {
for _, province := range country.Provinces {
os.MkdirAll(fmt.Sprintf("world/%s/%s", country.ID, province.ID), os.ModePerm)
printProvince(province, fmt.Sprintf("world/%s/%s/data.json", country.ID, province.ID))
}
printCountryFull(country, fmt.Sprintf("world/%s/full.json", country.ID))
printCountryData(country, fmt.Sprintf("world/%s/data.json", country.ID))
}
printWorldFull(world, "world/full.json")
printWorldData(world, "world/data.json")
// italy data
italy := parseItaly()
for _, regione := range italy.Regioni {
regID := slug.Make(regione.DenominazioneRegione)
for _, provincia := range regione.Province {
provID := slug.Make(provincia.SiglaProvincia)
if provID == "" {
provID = "xx"
}
os.MkdirAll(fmt.Sprintf("local/italy/%s/%s", regID, provID), os.ModePerm)
printProvincia(provincia, fmt.Sprintf("local/italy/%s/%s/data.json", regID, provID))
}
printRegioneFull(regione, fmt.Sprintf("local/italy/%s/full.json", regID))
printRegioneData(regione, fmt.Sprintf("local/italy/%s/data.json", regID))
}
printItalyFull(italy, "local/italy/full.json")
printItalyData(italy, "local/italy/data.json")
}
func printWorldFull(place World, out string) {
b, _ := json.Marshal(place)
_ = ioutil.WriteFile(out, b, 0644)
}
func printWorldData(place World, out string) {
for i := range place.Countries {
place.Countries[i].Timeseries = nil
place.Countries[i].Provinces = nil
}
b, _ := json.Marshal(place)
_ = ioutil.WriteFile(out, b, 0644)
}
func printCountryFull(place Country, out string) {
b, _ := json.Marshal(place)
_ = ioutil.WriteFile(out, b, 0644)
}
func printCountryData(place Country, out string) {
for i := range place.Provinces {
place.Provinces[i].Timeseries = nil
}
b, _ := json.Marshal(place)
_ = ioutil.WriteFile(out, b, 0644)
}
func printProvince(place Province, out string) {
b, _ := json.Marshal(place)
_ = ioutil.WriteFile(out, b, 0644)
}
// LOCAL - ITALY
func printItalyFull(italy Italy, out string) {
b, _ := json.Marshal(italy)
_ = ioutil.WriteFile(out, b, 0644)
}
func printItalyData(italy Italy, out string) {
for i := range italy.Regioni {
italy.Regioni[i].Timeseries = nil
italy.Regioni[i].Province = nil
}
b, _ := json.Marshal(italy)
_ = ioutil.WriteFile(out, b, 0644)
}
func printRegioneFull(regione Regione, out string) {
b, _ := json.Marshal(regione)
_ = ioutil.WriteFile(out, b, 0644)
}
func printRegioneData(regione Regione, out string) {
for i := range regione.Province {
regione.Province[i].Timeseries = nil
}
b, _ := json.Marshal(regione)
_ = ioutil.WriteFile(out, b, 0644)
}
func printProvincia(provincia Provincia, out string) {
b, _ := json.Marshal(provincia)
_ = ioutil.WriteFile(out, b, 0644)
}