-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (46 loc) · 1.14 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
package main
import (
"flag"
"fmt"
"sort"
)
var (
enableTips = flag.Bool("enable_tips", false, "Enable tips on the bottom of each message")
prodPtr = flag.Bool("prod", false, "Enables pushing to prod channel. Be careful!")
timePeriod = flag.String("time_period", "twoWeeks", "Defines the time period to grab stats for")
debug bool // equals !prod
)
type track struct {
Artist string
Name string
Playcount int
URL string
username string
}
func run() {
period := parseTimePeriod(*timePeriod)
from, to := timeframeToTime(period)
topTracks := make([]track, len(lastfmUsernames))
for i, username := range lastfmUsernames {
tr, err := getTopTrack(username, from, to)
if err != nil {
fmt.Printf("failed to get top track for '%s': %s\n", username, err)
return
}
topTracks[i] = tr
}
sort.Slice(topTracks, func(i, j int) bool {
return topTracks[i].Playcount > topTracks[j].Playcount
})
message := formatMessage(topTracks, period, from, to)
err := publishTracks(message)
if err != nil {
fmt.Printf("failed to push to telegram: %s\n", err)
return
}
}
func main() {
flag.Parse()
debug = !*prodPtr
run()
}