-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
49 lines (43 loc) · 877 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
45
46
47
48
49
package main
import (
"flag"
"time"
"github.com/smy20011/s1go/crawler"
"os"
"os/signal"
"syscall"
"log"
)
var (
interval = flag.Int64("interval", 3600, "Seconds between different fetch")
username = flag.String("username", "", "Stage1st username")
password = flag.String("password", "", "Stage1st password")
)
func main() {
flag.Parse()
c, err := crawler.NewCrawler()
if err != nil {
panic(err)
}
c.StartQueryServer()
defer c.Close()
trapCtrlCAndClose(c)
if len(*username) > 0 {
c.Login(*username, *password)
}
trigger := time.Tick(time.Second * time.Duration(*interval))
for {
c.FetchAllForums()
<-trigger
}
}
func trapCtrlCAndClose(c *crawler.Crawler) {
channel := make(chan os.Signal, 2)
signal.Notify(channel, os.Interrupt, syscall.SIGTERM)
go func() {
<- channel
log.Printf("Gracefully shutdown!")
c.Close()
os.Exit(0)
}()
}