task.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package services
  2. import (
  3. "context"
  4. "eta/eta_crawler/services/liangyou"
  5. "eta/eta_crawler/services/sci99"
  6. "eta/eta_crawler/utils"
  7. "fmt"
  8. "strconv"
  9. "time"
  10. "github.com/beego/beego/v2/task"
  11. )
  12. func Task() {
  13. //sync3()
  14. //syncAllComTradeMapping()
  15. //syncAllComTradeMapping2()
  16. //syncAllComTradeMapping3()
  17. //return
  18. fmt.Println("start crawler")
  19. //SyncRankingFromShangHai()
  20. //SyncRankingFromIne()
  21. //FileCoalCoastal()
  22. //FileCoalInland()
  23. if utils.BusinessCode == utils.BusinessCodeRelease {
  24. refreshData := task.NewTask("refreshData", "0 0,30 16-18 * * *", RefreshData)
  25. refreshEic := task.NewTask("RefreshEic", "0 0 2,6 * * *", RefreshEic)
  26. refreshCoal := task.NewTask("RefreshCoal", "0 0,30 16-23 * * *", RefreshCoal)
  27. refreshMeeting := task.NewTask("RefreshMeeting", "0 15 7-19/2 * * *", RefreshMeetingProbabilities)
  28. // refreshVisitors := task.NewTask("RefreshChangesVisitorsCovid", "0 30 2-22/10 * * *", RefreshChangesVisitorsCovid)
  29. syncEiaSteoData := task.NewTask("SyncEiaSteoData", "0 0 22 * * *", SyncEiaSteoData)
  30. syncYearComTrade := task.NewTask("SyncYearComTrade", "0 0 3 1 1 *", SyncYearComTrade) // 每年一月一号同步
  31. syncYearMonthComTrade := task.NewTask("SyncYearMonthComTrade", "0 0 3 1 * *", SyncYearMonthComTrade) // 每月1号同步
  32. crawlerIcpi := task.NewTask("refreshData", "0 0,30 16-23 * * *", CrawlerIcpi) //居民消费价格指数
  33. // 统计局-分月季年爬
  34. //refreshNationalMonthA := task.NewTask("RefreshNationalMonthDbA", "0 15 2 10 * *", national_data.RefreshNationalMonthDbA)
  35. //refreshNationalMonthB := task.NewTask("RefreshNationalMonthDbB", "0 15 2 16 * *", national_data.RefreshNationalMonthDbB)
  36. //refreshNationalQuarter := task.NewTask("RefreshNationalQuarterDb", "0 25 1 15 * *", national_data.RefreshNationalQuarterDb)
  37. //refreshNationalYearA := task.NewTask("RefreshNationalYearDbA", "0 45 1 20 * *", national_data.RefreshNationalYearDbA)
  38. //refreshNationalYearB := task.NewTask("RefreshNationalYearDbB", "0 45 1 25 * *", national_data.RefreshNationalYearDbB)
  39. task.AddTask("数据爬取", refreshData)
  40. task.AddTask("欧洲天然气爬取", refreshEic)
  41. task.AddTask("中国煤炭网爬取", refreshCoal)
  42. task.AddTask("美联储加息概率爬取", refreshMeeting)
  43. //task.AddTask("谷歌出行指数爬取", refreshVisitors)
  44. task.AddTask("eia steo报告", syncEiaSteoData) //每天22点爬一次
  45. task.AddTask("UN年度数据", syncYearComTrade) //每年一月一号的3点同步
  46. task.AddTask("UN月度数据", syncYearMonthComTrade) //每月1号的3点同步
  47. task.AddTask("居民消费价格指数", crawlerIcpi) //每月1号的3点同步
  48. }
  49. if utils.LY_OPEN == "1" {
  50. lyData := task.NewTask("refreshData", "0 0 12 * * *", liangyou.LyDataDeal) // 粮油商务网
  51. task.AddTask("粮油商务网", lyData)
  52. }
  53. if utils.BusinessCode == utils.BusinessCodeFuBang {
  54. // 仅富邦
  55. sci99.Scii99(nil)
  56. sci99 := task.NewTask("refreshSci99", "0 0,30 16-20 * * *", sci99.Scii99) //卓创资讯
  57. task.AddTask("卓创资讯", sci99)
  58. }
  59. if utils.BusinessCode == utils.BusinessCodeJinRui {
  60. crawlerSmm := task.NewTask("refreshShangHaiSmmData", "0 0 11-20 * * *", SyncShangHaiSmm) // 上海有色网爬虫
  61. task.AddTask("上海有色网指标爬取", crawlerSmm) //每天10-20点, 每小时爬一次
  62. crawlerSmmExcel := task.NewTask("refreshShangHaiSmmDataExcel", "0/30 * * * * *", SyncOldExcel) // 上海有色网爬虫
  63. task.AddTask("shanghaiOldExcel", crawlerSmmExcel) // 爬取成功后删除该任务
  64. }
  65. //task.AddTask("统计局数据爬取-月度A", refreshNationalMonthA) // 每月10号2:15执行
  66. //task.AddTask("统计局数据爬取-月度B", refreshNationalMonthB) // 每月16号2:15执行
  67. //task.AddTask("统计局数据爬取-季度", refreshNationalQuarter) // 每月15号1:25执行
  68. //task.AddTask("统计局数据爬取-年度A", refreshNationalYearA) // 每月20日1:45执行
  69. //task.AddTask("统计局数据爬取-年度B", refreshNationalYearB) // 每月25日1:45执行
  70. task.StartTask()
  71. //FileCoalJsm()
  72. //FileCoalFirm()
  73. //FileCoalCoastal()
  74. //FileCoalInland()
  75. //SyncRankingFromDalianSearch(0)
  76. fmt.Println("end crawler")
  77. }
  78. func RefreshData(cont context.Context) (err error) {
  79. //大连
  80. SyncRankingFromDalianSearch(0)
  81. SyncRankingFromZhengzhou()
  82. //SyncRankingFromShangHai()
  83. //SyncRankingFromIne()
  84. SyncRankingFromCffex()
  85. //SyncStorageFromEic()
  86. //广州期货交易所
  87. {
  88. n := 2
  89. //广州交易所期货-日行情
  90. for i := n; i >= 0; i-- {
  91. date := time.Now().AddDate(0, 0, -i)
  92. if date.Weekday() == time.Saturday || date.Weekday() == time.Sunday {
  93. continue
  94. }
  95. CrawlerFromGuangzhouDayQuotes(date)
  96. rn := utils.RangeRand(10, 60)
  97. fmt.Println("i:"+strconv.Itoa(i)+" date:", date.Format(utils.FormatDate)+";sleep:", strconv.Itoa(int(rn)))
  98. time.Sleep(time.Duration(rn) * time.Second)
  99. }
  100. //合约
  101. for i := n; i >= 0; i-- {
  102. date := time.Now().AddDate(0, 0, -i)
  103. if date.Weekday() == time.Saturday || date.Weekday() == time.Sunday {
  104. continue
  105. }
  106. fmt.Println("date:", date.Format(utils.FormatDate))
  107. CrawlerFromGuangzhouContract(date)
  108. rn := utils.RangeRand(3, 15)
  109. fmt.Println("i:"+strconv.Itoa(i)+" date:", date.Format(utils.FormatDate)+";sleep:", strconv.Itoa(int(rn)))
  110. time.Sleep(time.Duration(rn) * time.Second)
  111. }
  112. //日成交持仓排名
  113. for i := n; i >= 0; i-- {
  114. date := time.Now().AddDate(0, 0, -i)
  115. if date.Weekday() == time.Saturday || date.Weekday() == time.Sunday {
  116. continue
  117. }
  118. fmt.Println("date:", date.Format(utils.FormatDate))
  119. CrawlerFromGuangzhouDealPosiQuotes(date)
  120. rn := utils.RangeRand(3, 15)
  121. fmt.Println("i:"+strconv.Itoa(i)+" date:", date.Format(utils.FormatDate)+";sleep:", strconv.Itoa(int(rn)))
  122. time.Sleep(time.Duration(rn) * time.Second)
  123. }
  124. //广州交易所期货-仓单日报->开始日期:2023-06-20
  125. for i := n; i >= 0; i-- {
  126. date := time.Now().AddDate(0, 0, -i)
  127. if date.Weekday() == time.Saturday || date.Weekday() == time.Sunday {
  128. continue
  129. }
  130. fmt.Println("date:", date.Format(utils.FormatDate))
  131. CrawlerFromGuangzhouWbillWeeklyQuotes(date)
  132. rn := utils.RangeRand(3, 15)
  133. fmt.Println("i:"+strconv.Itoa(i)+" date:", date.Format(utils.FormatDate)+";sleep:", strconv.Itoa(int(rn)))
  134. time.Sleep(time.Duration(rn) * time.Second)
  135. }
  136. //一次性交割卖方仓单查询
  137. for i := n; i >= 0; i-- {
  138. date := time.Now().AddDate(0, -i, 0)
  139. fmt.Println("date:", date.Format(utils.FormatDate))
  140. CrawlerFromGuangzhouCongregateDeliveryQuotes(date)
  141. rn := utils.RangeRand(3, 15)
  142. fmt.Println("i:"+strconv.Itoa(i)+" date:", date.Format(utils.FormatDate)+";sleep:", strconv.Itoa(int(rn)))
  143. time.Sleep(time.Duration(rn) * time.Second)
  144. }
  145. //更新指标日期
  146. CrawlerFromGuangzhouIndexMinAndMaxDate()
  147. }
  148. return
  149. }
  150. func RefreshEic(cont context.Context) (err error) {
  151. SyncStorageFromEicV2()
  152. return
  153. }
  154. func RefreshCoal(cont context.Context) (err error) {
  155. FileCoalJsm()
  156. FileCoalFirm()
  157. FileCoalCoastal()
  158. FileCoalInland()
  159. return
  160. }
  161. func RefreshChangesVisitorsCovid(cont context.Context) (err error) {
  162. err = AddSourceChangesVisitorsCovid()
  163. return
  164. }
  165. //func Task2() {
  166. // fmt.Println("start")
  167. //
  168. // var cont context.Context
  169. // _ = national_data.RefreshNationalYearDbA(cont)
  170. //
  171. // //_ = national_data.RefreshNationalYearDbB(cont)
  172. //
  173. // //_ = national_data.ApiTest()
  174. // fmt.Println("end")
  175. //}
  176. func Task123() {
  177. fmt.Println("start")
  178. ctx := new(context.Context)
  179. CrawlerIcpi(*ctx)
  180. fmt.Println("end")
  181. }