-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathactions.go
62 lines (55 loc) · 1.38 KB
/
actions.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
package main
import (
"log"
"os"
"runtime"
"github.com/carlescere/scheduler"
"github.com/maddevsio/spiderwoman/lib"
"github.com/urfave/cli"
)
var path = Path{sqliteDBPath, lib.SourcesFilePath, lib.SourcesDefaultFilePath, lib.TypesFilePath, lib.TypesHDefaultFilePath}
func actionOnce(c *cli.Context) error {
initialize(path)
crawl(path)
grab(path)
return nil
}
func actionForever(c *cli.Context) error {
job := func() {
crawl(path)
grab(path)
}
initialize(path)
log.Print("All is OK. Starting cron job...")
if config.GetString("box") == "dev" {
log.Print("This is a dev box")
scheduler.Every(1).Minutes().Run(job)
//gocron.Every(1).Minute().Do(crawl) // this is for testing on dev box
} else {
log.Print("This is production")
if config.GetString("start-time") == "" {
log.Fatal("You need to set start-time value in config.yaml")
}
scheduler.Every().Day().At(config.GetString("start-time")).Run(job)
//gocron.Every(1).Day().At().Do(crawl, path)
}
//<- gocron.Start()
runtime.Goexit()
return nil
}
func actionExcel(c *cli.Context) error {
err := os.MkdirAll(config.GetString("xls-dir"), 0777)
if err != nil {
log.Fatalf("cannot create dir for excel files: %v", err)
}
if c.Args().Get(0) != "noinit" {
initialize(path)
}
createAllXLSByDays(path.SqliteDBPath)
return nil
}
func actionGrab(c *cli.Context) error {
initialize(path)
grab(path)
return nil
}