-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (46 loc) · 1.06 KB
/
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
50
51
52
53
54
55
56
57
58
59
package main
import (
"spider/method"
"spider/model"
"github.com/gin-gonic/gin"
"github.com/robfig/cron"
)
func main() {
go fetchNews()
web()
}
func web(){
gin.SetMode(gin.ReleaseMode)
r:=gin.Default()
r.GET("/AllNews",func(ctx *gin.Context) {
ctx.JSON(200,model.GetAllBadNews())
})
r.GET("/News/:Category",func(ctx *gin.Context) {
c:=ctx.Param("Category")
ctx.JSON(200,model.GetSingleCategoryBadNews(c))
})
r.Run(":8080")
}
func fetchNews(){
model.NewBaiduNewsSlice()
model.NewBadBaiduNewsSlice()
DoSyncTaskCronJob()
}
//定时1分钟判断新闻是否更新并抓取
func DoSyncTaskCronJob(){
c := cron.New()
spec:="00 * * * * ?"
f:=method.FetchMethod{}
c.AddFunc(spec,f.Fetch_activte)
c.AddFunc(spec,f.Fetch_Discovery)
c.AddFunc(spec,f.Fetch_Entertainment)
c.AddFunc(spec,f.Fetch_Finance)
c.AddFunc(spec,f.Fetch_Health)
c.AddFunc(spec,f.Fetch_Internet)
c.AddFunc(spec,f.Fetch_Lady)
c.AddFunc(spec,f.Fetch_Military)
c.AddFunc(spec,f.Fetch_World)
c.AddFunc(spec,f.Fetch_Sports)
c.AddFunc(spec,f.Fetch_Technology)
c.Start()
}