-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (49 loc) · 1.34 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
package main
import (
"fmt"
"os"
"time"
"github.com/nce/ics2mattermost/icsparser"
"github.com/nce/ics2mattermost/logger"
"github.com/nce/ics2mattermost/mattermost"
"github.com/go-co-op/gocron"
"strings"
_ "embed"
)
//go:generate sh setVersion.sh
//go:embed version
var Version string
func checkIfEmpty(env string) string {
ret, ok := os.LookupEnv(env)
if !ok {
logger.Fatal(fmt.Sprintf("ENV Var '%s' not set; Check help", env))
}
return ret
}
func main() {
logger.SetupLogging(strings.ToLower("debug"))
logger.Info(fmt.Sprintf("Application version %s", Version))
var icsUrl, icsUser, icsToken, mattermostUrl string
icsUrl = checkIfEmpty("ICS_URL")
icsUser = checkIfEmpty("ICS_USER")
icsToken = checkIfEmpty("ICS_TOKEN")
mattermostUrl = checkIfEmpty("MATTERMOST_URL")
webhook := mattermost.Setup(mattermostUrl)
s := gocron.NewScheduler(time.Local)
//s.Every(1).Weeks().Monday().Tuesday().Wednesday().Thursday().At("8:30").Do(func() {
s.Every(20).Seconds().Do(func() {
cal := icsparser.Setup(
icsUrl,
icsUser,
icsToken)
cal.GetTodaysEvents()
dailyMessage, err := cal.PrepareDailyIngest()
if err == nil {
webhook.Send(dailyMessage)
} else {
logger.Error(
fmt.Sprintf("could not prepare daily: %s", err.Error()))
}
})
s.StartBlocking()
}