-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.go
88 lines (78 loc) · 1.68 KB
/
run.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"hotsearch/log"
"hotsearch/pool"
"hotsearch/target"
"hotsearch/utils"
"os"
"os/signal"
"syscall"
"time"
)
func run() {
k := new(utils.Keyword)
handle := NewHandleData()
k.Exist = new(utils.Check)
k.Tick = time.NewTicker(time.Second / 2)
handle.Ticker = time.NewTicker(TimeSleep)
go handle.Handle()
tableName := []string{
"bilibili",
"douyin",
"weibo",
"weibu",
"cnvd",
"freebuf",
"keywords",
}
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGTERM, os.Interrupt)
b := pool.NewBufferPool()
c := pool.NewClient()
database := utils.NewDatabase(DbPath)
targets := target.NewTargets(b, c)
cnvd := target.NewCnvd(b, c)
go handle.PutRun(targets, cnvd)
noFindTable := database.FindTable(tableName...)
for i := 0; i < len(noFindTable); i++ {
database.CreateTable(noFindTable[i])
}
for {
select {
case <-s:
die(handle, database, b, c)
k.Tick.Stop()
handle.Ticker.Stop()
case d, ok := <-handle.Data:
if !ok {
return
}
for website, datas := range d {
log.LogPut("[INFO] Get Data %s %d\n", website, len(datas))
for num := 0; num < len(datas); num++ {
noFindTable = database.FindTable(website)
for i := 0; i < len(noFindTable); i++ {
if !database.CreateTable(noFindTable[i]) {
goto jump
}
}
if !database.InsertData(website, datas[num]) {
log.LogPut("[WARNING] Insert %s %s Error", website, datas[num])
goto jump
}
}
jump:
database.Deduplication(website)
}
case <-k.Tick.C:
handle.Keywords = k.Keywords(KeywordPath)
}
}
}
func die(c ...Close) {
for i := 0; i < len(c); i++ {
c[i].Close()
}
log.LogPut("Done……")
os.Exit(0)
}