-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (57 loc) · 1.26 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
package main
import (
"flag"
"log"
"sort"
"time"
)
func main() {
err := parseFlags()
if err != nil {
log.Println(err)
flag.Usage()
return
}
for range time.Tick(10 * time.Second) {
checkForEarlierSlot()
}
}
func checkForEarlierSlot() {
slots := getSlotsForAuthorities()
if len(slots) <= 0 {
log.Println("no slots found")
return
}
earliestSlot := getEarliestSlot(slots)
if earliestSlot.StartDate.Before(date) {
handleFoundSlot(earliestSlot)
return
}
log.Printf("no earlier slot found. earliest slot on %s\n", earliestSlot.StartDate.Format(time.RFC822))
}
func getSlotsForAuthorities() []slot {
var slots []slot
for _, authority := range authorities {
slotsOfAuthority, err := getCovidVaccinationSlots(authority)
if err != nil {
log.Fatal(err)
}
for _, slot := range slotsOfAuthority {
slots = append(slots, slot)
}
}
return slots
}
func getEarliestSlot(slots []slot) slot {
sort.Slice(slots, func(i, j int) bool {
return slots[i].StartDate.Before(slots[j].StartDate)
})
return slots[0]
}
func handleFoundSlot(earliestSlot slot) {
log.Printf("YEAHHH. found an earlier slot on %s\n", earliestSlot.StartDate.Format(time.RFC822))
err := sendPushNotification(earliestSlot.StartDate)
if err != nil {
log.Fatal(err)
}
}