task.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package services
  2. import (
  3. "context"
  4. "eta/eta_crawler/services/email"
  5. "eta/eta_crawler/services/liangyou"
  6. "eta/eta_crawler/services/sci99"
  7. "eta/eta_crawler/utils"
  8. "fmt"
  9. "strconv"
  10. "time"
  11. "github.com/beego/beego/v2/task"
  12. )
  13. func Task() {
  14. //sync3()
  15. //syncAllComTradeMapping()
  16. //syncAllComTradeMapping2()
  17. //syncAllComTradeMapping3()
  18. //return
  19. fmt.Println("start crawler")
  20. //SyncRankingFromShangHai()
  21. //SyncRankingFromIne()
  22. //FileCoalCoastal()
  23. //FileCoalInland()
  24. if utils.BusinessCode == utils.BusinessCodeRelease {
  25. refreshUsdaPsd := task.NewTask("RefreshUsdaPsd", "0 0 16,19 * * 1,5", DownloadUsdaPsdDataTask) //每周一五下午16点,19点
  26. refreshUsdaFms := task.NewTask("RefreshUsdaFms", "0 0 16,19 * * 1,5", DownloadUsdaFmsDataTask) //每周一五下午16点,19点
  27. refreshData := task.NewTask("refreshData", "0 0,30 16-18 * * *", RefreshData)
  28. refreshEic := task.NewTask("RefreshEic", "0 0 2,6 * * *", RefreshEic)
  29. // 已经使用另外的任务去监听中国煤炭网邮件附件
  30. // refreshCoal := task.NewTask("RefreshCoal", "0 0,30 16-23 * * *", RefreshCoal)
  31. refreshMeeting := task.NewTask("RefreshMeeting", "0 15 7-19/2 * * *", RefreshMeetingProbabilities)
  32. // refreshVisitors := task.NewTask("RefreshChangesVisitorsCovid", "0 30 2-22/10 * * *", RefreshChangesVisitorsCovid)
  33. syncEiaSteoData := task.NewTask("SyncEiaSteoData", "0 0 22 * * *", SyncEiaSteoData)
  34. syncYearComTrade := task.NewTask("SyncYearComTrade", "0 0 3 1 1 *", SyncYearComTrade) // 每年一月一号同步
  35. syncYearMonthComTrade := task.NewTask("SyncYearMonthComTrade", "0 0 3 1 * *", SyncYearMonthComTrade) // 每月1号同步
  36. crawlerIcpi := task.NewTask("refreshData", "0 0,30 16-23 * * *", CrawlerIcpi) //居民消费价格指数
  37. downloadGPRRiskTask := task.NewTask("DownloadGPRRiskTask", "0 0,30 16-19 * * *", DownloadGPRRiskTask) //每天下午16点至19点,每隔半小时
  38. // 统计局-分月季年爬
  39. //refreshNationalMonthA := task.NewTask("RefreshNationalMonthDbA", "0 15 2 10 * *", national_data.RefreshNationalMonthDbA)
  40. //refreshNationalMonthB := task.NewTask("RefreshNationalMonthDbB", "0 15 2 16 * *", national_data.RefreshNationalMonthDbB)
  41. //refreshNationalQuarter := task.NewTask("RefreshNationalQuarterDb", "0 25 1 15 * *", national_data.RefreshNationalQuarterDb)
  42. //refreshNationalYearA := task.NewTask("RefreshNationalYearDbA", "0 45 1 20 * *", national_data.RefreshNationalYearDbA)
  43. //refreshNationalYearB := task.NewTask("RefreshNationalYearDbB", "0 45 1 25 * *", national_data.RefreshNationalYearDbB)
  44. task.AddTask("美国农业部月度供需数据爬取", refreshUsdaPsd)
  45. task.AddTask("美国农业部出口销售数据爬取", refreshUsdaFms)
  46. task.AddTask("GPR地缘风险指数爬取", downloadGPRRiskTask)
  47. task.AddTask("数据爬取", refreshData)
  48. task.AddTask("欧洲天然气爬取", refreshEic)
  49. // task.AddTask("中国煤炭网爬取", refreshCoal)
  50. task.AddTask("美联储加息概率爬取", refreshMeeting)
  51. //task.AddTask("谷歌出行指数爬取", refreshVisitors)
  52. task.AddTask("eia steo报告", syncEiaSteoData) //每天22点爬一次
  53. task.AddTask("UN年度数据", syncYearComTrade) //每年一月一号的3点同步
  54. task.AddTask("UN月度数据", syncYearMonthComTrade) //每月1号的3点同步
  55. task.AddTask("居民消费价格指数", crawlerIcpi) //每月1号的3点同步
  56. }
  57. if utils.LY_OPEN == "1" {
  58. lyData := task.NewTask("refreshData", "0 0 12 * * *", liangyou.LyDataDeal) // 粮油商务网
  59. task.AddTask("粮油商务网", lyData)
  60. }
  61. if utils.BusinessCode == utils.BusinessCodeFuBang {
  62. // 仅富邦
  63. sci99.Scii99(nil)
  64. sci99 := task.NewTask("refreshSci99", "0 0,30 16-20 * * *", sci99.Scii99) //卓创资讯
  65. task.AddTask("卓创资讯", sci99)
  66. }
  67. if utils.BusinessCode == utils.BusinessCodeJinRui {
  68. crawlerSmm := task.NewTask("refreshShangHaiSmmData", "0 0 11-20 * * *", SyncShangHaiSmm) // 上海有色网爬虫
  69. task.AddTask("上海有色网指标爬取", crawlerSmm) //每天10-20点, 每小时爬一次
  70. crawlerSmmExcel := task.NewTask("refreshShangHaiSmmDataExcel", "0/30 * * * * *", SyncOldExcel) // 上海有色网爬虫
  71. task.AddTask("shanghaiOldExcel", crawlerSmmExcel) // 爬取成功后删除该任务
  72. }
  73. //task.AddTask("统计局数据爬取-月度A", refreshNationalMonthA) // 每月10号2:15执行
  74. //task.AddTask("统计局数据爬取-月度B", refreshNationalMonthB) // 每月16号2:15执行
  75. //task.AddTask("统计局数据爬取-季度", refreshNationalQuarter) // 每月15号1:25执行
  76. //task.AddTask("统计局数据爬取-年度A", refreshNationalYearA) // 每月20日1:45执行
  77. //task.AddTask("统计局数据爬取-年度B", refreshNationalYearB) // 每月25日1:45执行
  78. if utils.CoalOpen == "1" {
  79. mtjh := task.NewTask("refreshMtjh", "0 */2 * * * *", CoalWatchTask)
  80. task.AddTask("启动中国煤炭网监听excel脚本", mtjh)
  81. }
  82. if utils.CoalMailAttachmentOpen == "1" {
  83. coalMailTask := task.NewTask("MailAttachment", utils.CoalMailAttachmentTime, email.ListenMail)
  84. task.AddTask("启动获取邮件附件脚本", coalMailTask)
  85. }
  86. task.StartTask()
  87. //FileCoalJsm()
  88. //FileCoalFirm()
  89. //FileCoalCoastal()
  90. //FileCoalInland()
  91. //SyncRankingFromDalianSearch(0)
  92. fmt.Println("end crawler")
  93. }
  94. func RefreshData(cont context.Context) (err error) {
  95. //大连
  96. SyncRankingFromDalianSearch(0)
  97. SyncRankingFromZhengzhou()
  98. //SyncRankingFromShangHai()
  99. //SyncRankingFromIne()
  100. SyncRankingFromCffex()
  101. //SyncStorageFromEic()
  102. //广州期货交易所
  103. {
  104. n := 2
  105. //广州交易所期货-日行情
  106. for i := n; i >= 0; i-- {
  107. date := time.Now().AddDate(0, 0, -i)
  108. if date.Weekday() == time.Saturday || date.Weekday() == time.Sunday {
  109. continue
  110. }
  111. CrawlerFromGuangzhouDayQuotes(date)
  112. rn := utils.RangeRand(10, 60)
  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. CrawlerFromGuangzhouContract(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. //日成交持仓排名
  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. CrawlerFromGuangzhouDealPosiQuotes(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. //广州交易所期货-仓单日报->开始日期:2023-06-20
  141. for i := n; i >= 0; i-- {
  142. date := time.Now().AddDate(0, 0, -i)
  143. if date.Weekday() == time.Saturday || date.Weekday() == time.Sunday {
  144. continue
  145. }
  146. fmt.Println("date:", date.Format(utils.FormatDate))
  147. CrawlerFromGuangzhouWbillWeeklyQuotes(date)
  148. rn := utils.RangeRand(3, 15)
  149. fmt.Println("i:"+strconv.Itoa(i)+" date:", date.Format(utils.FormatDate)+";sleep:", strconv.Itoa(int(rn)))
  150. time.Sleep(time.Duration(rn) * time.Second)
  151. }
  152. //一次性交割卖方仓单查询
  153. for i := n; i >= 0; i-- {
  154. date := time.Now().AddDate(0, -i, 0)
  155. fmt.Println("date:", date.Format(utils.FormatDate))
  156. CrawlerFromGuangzhouCongregateDeliveryQuotes(date)
  157. rn := utils.RangeRand(3, 15)
  158. fmt.Println("i:"+strconv.Itoa(i)+" date:", date.Format(utils.FormatDate)+";sleep:", strconv.Itoa(int(rn)))
  159. time.Sleep(time.Duration(rn) * time.Second)
  160. }
  161. //更新指标日期
  162. CrawlerFromGuangzhouIndexMinAndMaxDate()
  163. }
  164. return
  165. }
  166. func RefreshEic(cont context.Context) (err error) {
  167. SyncStorageFromEicV2()
  168. return
  169. }
  170. func RefreshCoal(cont context.Context) (err error) {
  171. FileCoalJsm()
  172. FileCoalFirm()
  173. FileCoalCoastal()
  174. FileCoalInland()
  175. return
  176. }
  177. func RefreshChangesVisitorsCovid(cont context.Context) (err error) {
  178. err = AddSourceChangesVisitorsCovid()
  179. return
  180. }
  181. //func Task2() {
  182. // fmt.Println("start")
  183. //
  184. // var cont context.Context
  185. // _ = national_data.RefreshNationalYearDbA(cont)
  186. //
  187. // //_ = national_data.RefreshNationalYearDbB(cont)
  188. //
  189. // //_ = national_data.ApiTest()
  190. // fmt.Println("end")
  191. //}
  192. func Task123() {
  193. fmt.Println("start")
  194. ctx := new(context.Context)
  195. CrawlerIcpi(*ctx)
  196. fmt.Println("end")
  197. }