-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscrape.go
66 lines (50 loc) · 1.05 KB
/
scrape.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
package main
import (
"log"
"time"
)
var conf Config
var db *Database
func cleanKeys() {
now := time.Now()
max := time.Duration(conf.MaxTime) * time.Second
for key, _ := range conf.keys {
if now.Sub(conf.keys[key]) > max {
delete(conf.keys, key)
}
}
}
func initDatabase() {
db.CreateBucket("pastes")
for _, kw := range conf.Keywords {
db.CreateBucket(kw.Bucket)
}
for _, re := range conf.Regexes {
db.CreateBucket(re.Bucket)
}
}
func scrape(piChan chan<- *ProcessItem) {
for {
scrapeGithubEvents(piChan)
scrapePastes(piChan)
scrapeGists(piChan)
scrapeFiles(piChan)
log.Printf("[*] Sleeping for %d seconds", conf.Sleep)
time.Sleep(time.Duration(conf.Sleep) * time.Second)
cleanKeys()
}
}
func main() {
conf = newConfig()
db = newDatabase(conf.DbFile)
if db != nil {
initDatabase()
go startWebServer()
processItemChan := make(chan *ProcessItem, 100)
processSemaphore := make(chan struct{}, 10)
go scrape(processItemChan)
for item := range processItemChan {
go process(processSemaphore, item)
}
}
}