-
Notifications
You must be signed in to change notification settings - Fork 0
/
kpg.go
45 lines (36 loc) · 886 Bytes
/
kpg.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 (
"fmt"
"log"
)
func main() {
readEnvironment("kpg.env")
loadHistory()
current := retrieveCurrentData()
var tendency string
var icon rune
diff, err := levelDifference(current, 240)
if err != nil {
tendency = "?"
icon = 0
} else {
tendency, icon = getTendencyString(diff)
}
statusText := prepareStatusString(current, tendency, icon)
doPost := checkIfPostNow(current)
if doPost {
id, err := postToMastodon(statusText)
if err != nil {
log.Printf("%v [%v: %v] - error: %v\n", current, diff, tendency, err)
} else {
fmt.Printf("%v [%v: %v] - %v\n", current, diff, tendency, id)
savePostTime(current)
}
} else {
fmt.Printf("%v [%v: %v] - no post\n", current, diff, tendency)
}
if len(history) == 0 || history[len(history)-1].Timestamp.Before(current.Timestamp) {
history = append(history, current)
saveHistory()
}
}