-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
59 lines (44 loc) · 1.04 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
/*
* Copyright (C) 2018 Aurélien Chabot <aurelien@chabot.fr>
*
* SPDX-License-Identifier: MIT
*/
package main
import (
"fmt"
"os"
)
import "github.com/jessevdk/go-flags"
import "github.com/jasonlvhit/gocron"
type options struct {
Config string `short:"c" long:"conf" description:"Config file" default:"/etc/transmission-rss.conf"`
}
var opt options
var parser = flags.NewParser(&opt, flags.Default)
func main() {
if _, err := parser.Parse(); err != nil {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
os.Exit(0)
} else {
os.Exit(1)
}
}
config := NewConfig(opt.Config)
client := NewTransmission(fmt.Sprintf("%s:%s",
config.Server.Host, config.Server.Port))
cache := NewCache()
update := func() {
for _, feed := range config.Feeds {
aggregator := NewAggregator(feed, cache)
urls := aggregator.GetNewTorrentURL()
for _, url := range urls {
client.Add(url)
}
}
}
// Run now
update()
// Schedule
gocron.Every(config.UpdateInterval).Minutes().Do(update)
<-gocron.Start()
}