-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteamerSummary.go
45 lines (41 loc) · 1.08 KB
/
steamerSummary.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
)
type SteamerSummary struct {
Developers map[string][]string `json:"developers"`
Games int `json:"games"`
Genres map[string]int `json:"genres"`
PagesFrom int `json:"pages_from"`
PagesTo int `json:"pages_to"`
Publishers map[string][]string `json:"publishers"`
Sentiments map[string]int `json:"sentiments"`
}
func writeSteamerSummary(fullpath string, s *SteamerSummary) error {
err := os.MkdirAll(fullpath, os.ModePerm)
if err != nil {
return err
}
b, err := json.Marshal(s)
if err != nil {
return err
}
filename := fmt.Sprintf("%d-%d-summary.json", s.PagesFrom, s.PagesTo)
fullname := filepath.Join(fullpath, filename)
err = ioutil.WriteFile(fullname, b, os.ModePerm)
return err
}
func writeSteamerSummaryDefault(s *SteamerSummary) error {
user, err := user.Current()
if err != nil {
panic(err)
}
fullpath := filepath.Join(user.HomeDir, "Desktop", "steambot")
err = writeSteamerSummary(fullpath, s)
return err
}