-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_extractor.go
More file actions
42 lines (36 loc) · 967 Bytes
/
csv_extractor.go
File metadata and controls
42 lines (36 loc) · 967 Bytes
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
package main
import (
"fmt"
"bytes"
"os"
"github.com/Chimpcode/bombo-open-api/scraper"
)
func CreateCSVFromStruct(teams map[string]*scraper.Team) {
buffer := bytes.NewBufferString("")
for _, team := range teams {
for _, player := range team.GoalKeeper {
s := fmt.Sprintf("%s,%s,%d\n", player.Name, player.Team, player.Cost)
buffer.Write([]byte(s))
}
for _, player := range team.Defender {
s := fmt.Sprintf("%s,%s,%d\n", player.Name, player.Team, player.Cost)
buffer.Write([]byte(s))
}
for _, player := range team.MidFielder {
s := fmt.Sprintf("%s,%s,%d\n", player.Name, player.Team, player.Cost)
buffer.Write([]byte(s))
}
for _, player := range team.Forwarder {
s := fmt.Sprintf("%s,%s,%d\n", player.Name, player.Team, player.Cost)
buffer.Write([]byte(s))
}
}
file, err := os.Create("./data/league_csv.csv")
if err != nil {
panic(err)
}
_, err = file.Write(buffer.Bytes())
if err != nil {
panic(err)
}
}