-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (37 loc) · 1.05 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
package main
import (
"strconv"
"time"
"github.com/IvoGoman/portalnotifier/database"
"github.com/IvoGoman/portalnotifier/login"
"github.com/IvoGoman/portalnotifier/util"
"github.com/IvoGoman/portalnotifier/html"
"os"
)
var path, _ = os.Getwd()
var configPath = path + "/portalnotifier/config.yml"
var config = util.LoadConfig(configPath)
var gradesKnown = make(map[string]util.Module)
func main() {
database.CreateDB()
gradesKnown = database.SelectGrades()
interval, _ := strconv.Atoi(config["interval"])
go html.Serve(config)
grades := login.GetGrades(config)
checkGrades(gradesKnown, grades)
gradeTicker := time.NewTicker(time.Minute * time.Duration(interval))
for range gradeTicker.C {
grades := login.GetGrades(config)
checkGrades(gradesKnown, grades)
}
}
func checkGrades(known map[string]util.Module, current map[string]util.Module) {
for k := range known {
delete(current, k)
}
if len(current) > 0 {
database.StoreGrades(current)
known = database.SelectGrades()
util.SendMail(config, current, util.CalculateAverage(known))
}
}