-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
71 lines (62 loc) · 1.46 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
package main
import (
"log"
"os"
)
func main() {
if len(os.Args) < 2 {
log.Println("need at least one arg list-stores || info-stores || info-societes")
os.Exit(0)
}
arg := os.Args[1]
log.Printf("args are %s\n", os.Args)
if arg == "list-stores" || arg == "ls" {
getStoresIdsAndWrite()
} else if arg == "info-stores" || arg == "is" {
getStoresInfosAndWrite()
} else if arg == "info-societes" || arg == "ic" {
getInfoCompanyAndWrite()
}
}
func getStoresIdsAndWrite() {
storesIDs, err := getListStores()
if err != nil {
log.Fatal("can't get storesIds")
}
writeStoresIDs(storesIDs)
}
func getStoresInfosAndWrite() {
csvLines, err := readFromCsv("store.csv")
if err != nil {
log.Fatalf("can't read csv=> %s", err)
}
for index, l := range csvLines {
storeID := l[0]
storeInfo, err := getStoresInfo(storeID)
if err != nil {
log.Fatal(err)
}
l = append(l, storeInfo.Name)
l = append(l, storeInfo.CompanyName)
l = append(l, storeInfo.Coordinates)
l = append(l, storeInfo.RestaurantAddress)
csvLines[index] = l
}
writeCsv(csvLines, "info_stores.csv")
}
func getInfoCompanyAndWrite() {
csvLines, err := readFromCsv("info_stores.csv")
if err != nil {
log.Fatalf("can't read csv=> %s", err)
}
for index, l := range csvLines {
companyName := l[2]
companyInfos := getInfoCompany(companyName)
if err != nil {
log.Fatal(err)
}
l = append(l, companyInfos...)
csvLines[index] = l
}
writeCsv(csvLines, "info_company.csv")
}