-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (37 loc) · 979 Bytes
/
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
package main
import (
"github.com/fsnotify/fsnotify"
"github.com/pkg/errors"
"github.com/spf13/viper"
"log"
"roob.re/horriblefeed"
"time"
)
func main() {
config := viper.New()
config.SetConfigName("horriblefeed")
config.AddConfigPath(".")
config.AddConfigPath("$XDG_CONFIG_HOME/horriblefeed")
config.AddConfigPath("$HOME/.config/horriblefeed")
config.SetDefault("intervalMinutes", 10)
if err := config.ReadInConfig(); err != nil {
log.Fatal(errors.WithMessage(err, "could not read config file"))
}
hf, err := horriblefeed.New(config)
if err != nil {
log.Fatal(err)
}
config.WatchConfig()
config.OnConfigChange(func(e fsnotify.Event) {
log.Println("Reloading config file...")
if hf.UseFeeds(config) == nil {
log.Println("Feeds reloaded successfully.")
} else {
log.Println("Error reloading feeds. No changes were made.")
}
})
for {
hf.ParseAndAdd()
time.Sleep(time.Duration(config.GetInt64("intervalMinutes")) * time.Minute)
}
}