-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawl.go
52 lines (42 loc) · 943 Bytes
/
crawl.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
package crawl
import (
"fmt"
"log"
"os"
"runtime"
)
const configFile = "conf/app.conf"
var (
ch1 chan string
ch2 chan string
ch3 chan int
novelDir string
config map[string]string
)
func init() {
ch1 = make(chan string, 20)
ch2 = make(chan string, 1000)
ch3 = make(chan int, 1000)
config, _ := getConfig(configFile)
logfile, err := os.OpenFile(config["LOG_FILE"], os.O_CREATE|os.O_RDWR|os.O_APPEND, 0777)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
log.SetOutput(logfile)
}
// DownloadNovels export
func DownloadNovels() {
runtime.GOMAXPROCS(runtime.NumCPU())
createDirIfNotExists(config["DOWNLOAD_FOLDER"])
go getChapterListURL(config["NOVEL_URL"])
go getChapterNumber(config["SUFFIX"])
go downloadNovel()
count := 0
for num := range ch3 {
count = count + num
fmt.Println("count:", count)
}
fmt.Println("crawl end")
}