-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteamGameSummary.go
176 lines (163 loc) · 6.28 KB
/
steamGameSummary.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"
"time"
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
type SteamGameSummary struct {
Available bool `json:"available"`
AverageDecline int `json:"average_decline"`
AverageGain int `json:"average_gain"`
AverageMaxPlayerCount int `json:"average_max_player_count"`
AverageMinPlayerCount int `json:"average_min_player_count"`
AveragePlayerCount int `json:"average_player_count"`
Categories []string `json:"categories"`
ComingSoon bool `json:"coming_soon"`
Developers []string `json:"developers"`
EarlyAccess bool `json:"early_access"`
Genres []string `json:"genres"`
Name string `json:"name"`
MonthsSinceRelease int `json:"months_since_release"`
PeakPlayers int `json:"peak_players"`
PeakPlayersDate string `json:"peak_players_date"`
PlayerPeak24Hour int `json:"player_peak_24_hour"`
PlayerPeakAll int `json:"player_peak_all"`
Publishers []string `json:"publishers"`
ReleaseDate time.Time `json:"release_date"`
ReviewsAllCount int `json:"reviews_all_count"`
ReviewsAllSentiment string `json:"reviews_all_sentiment"`
ReviewsRecentCount int `json:"reviews_recent_count"`
ReviewsRecentSentiment string `json:"reviews_recent_sentiment"`
SocialMedia []string `json:"social_media"`
Tags []string `json:"tags"`
Timestamp time.Time `json:"timestamp"`
Title string `json:"title"`
TroughPlayers int `json:"trough_players"`
TroughPlayersDate string `json:"trough_players_date"`
URL string `json:"URL"`
Website string `json:"website"`
YearsSinceRelease int `json:"years_since_release"`
}
func NewSteamGameSummary(steamGamePage *SteamGamePage, steamChartPage *SteamChartPage) *SteamGameSummary {
steamGameSummaryStatistics := NewSteamGameSummaryStatistics(steamChartPage)
return &SteamGameSummary{
Available: steamGamePage.Available,
AverageDecline: steamGameSummaryStatistics.AverageDecline,
AverageGain: steamGameSummaryStatistics.AverageGain,
AverageMaxPlayerCount: steamGameSummaryStatistics.AverageMaxPlayerCount,
AverageMinPlayerCount: steamGameSummaryStatistics.AverageMinPlayerCount,
AveragePlayerCount: steamGameSummaryStatistics.AveragePlayerCount,
Categories: parseSteamGameSummaryCategories(&steamGamePage.Categories),
ComingSoon: steamGamePage.ComingSoon,
Developers: parseSteamGameSummaryDevelopers(&steamGamePage.Developers),
EarlyAccess: steamGamePage.EarlyAccess,
Genres: parseSteamGameSummaryGenres(&steamGamePage.Genres),
Name: steamGamePage.Name,
MonthsSinceRelease: steamGameSummaryStatistics.MonthsSinceRelease,
PeakPlayers: steamGameSummaryStatistics.PeakPlayers,
PeakPlayersDate: steamGameSummaryStatistics.PeakPlayersDate,
PlayerPeak24Hour: steamChartPage.PlayerPeak24Hour,
PlayerPeakAll: steamChartPage.PlayerPeakAll,
Publishers: parseSteamGameSummaryPublishers(&steamGamePage.Publishers),
ReleaseDate: steamGamePage.ReleaseDate,
ReviewsAllCount: steamGamePage.ReviewsAll.Count,
ReviewsAllSentiment: steamGamePage.ReviewsAll.Sentiment,
ReviewsRecentCount: steamGamePage.ReviewsRecent.Count,
ReviewsRecentSentiment: steamGamePage.ReviewsRecent.Sentiment,
SocialMedia: parseSteamGameSummarySocialMedia(&steamGamePage.SocialMedia),
Tags: parseSteamGameSummaryTags(&steamGamePage.Tags),
Timestamp: time.Now(),
Title: parseSteamGameSummaryTitle(steamGamePage.Title),
TroughPlayers: steamGameSummaryStatistics.TroughPlayers,
TroughPlayersDate: steamGameSummaryStatistics.TroughPlayersDate,
URL: steamGamePage.URL,
Website: steamGamePage.Website,
YearsSinceRelease: steamGameSummaryStatistics.YearsSinceRelease}
}
func parseSteamGameSummaryCategories(s *[]SteamPageGameCategory) []string {
v := *s
categories := make([]string, len(v))
for i, p := range v {
categories[i] = p.Name
}
return categories
}
func parseSteamGameSummaryDevelopers(s *[]SteamPageGameDeveloper) []string {
v := *s
developers := make([]string, len(v))
for i, p := range v {
developers[i] = p.Name
}
return developers
}
func parseSteamGameSummaryGenres(s *[]SteamPageGameGenre) []string {
v := *s
genres := make([]string, len(v))
for i, p := range v {
genres[i] = p.Name
}
return genres
}
func parseSteamGameSummaryPublishers(s *[]SteamPageGamePublisher) []string {
v := *s
publishers := make([]string, len(v))
for i, p := range v {
publishers[i] = p.Name
}
return publishers
}
func parseSteamGameSummarySocialMedia(s *[]SteamGameSocialMedia) []string {
v := *s
social := make([]string, len(v))
for i, p := range v {
social[i] = p.URL
}
return social
}
func parseSteamGameSummaryTags(s *[]SteamPageGameTag) []string {
v := *s
tags := make([]string, len(v))
for i, p := range v {
tags[i] = p.Name
}
return tags
}
func parseSteamGameSummaryTitle(s string) string {
transformer := transform.Chain(norm.NFD, transform.RemoveFunc(func(r rune) bool { return unicode.Is(unicode.Mn, r) }), norm.NFC)
x, _, err := transform.String(transformer, s)
if err != nil {
return s
}
return x
}
func writeSteamGameSummary(fullpath string, s *SteamGameSummary) 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("summary-%s.json", strings.ToLower(s.Name))
fullname := filepath.Join(fullpath, filename)
err = ioutil.WriteFile(fullname, b, os.ModePerm)
return err
}
func writeSteamGameSummaryDefault(s *SteamGameSummary) error {
user, err := user.Current()
if err != nil {
panic(err)
}
fullpath := filepath.Join(user.HomeDir, "Desktop", "steambot", "games", s.Name)
err = writeSteamGameSummary(fullpath, s)
return err
}