task.go 7.8 KB

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