get_order.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. from app.api_data.order_util import *
  2. from model.DataBaseUtils import MysqlUtils
  3. from concurrent.futures import ThreadPoolExecutor
  4. from model.DingTalkUtils import DingTalkUtils,DingTalkDecorators
  5. from app.api_data.platform_order.audio_qiyue import AudioQiyue
  6. from app.api_data.platform_order.youshuge import get_youshuge_order_task
  7. from app.api_data.platform_order.yuewen import get_yuewen_order_task
  8. db = MysqlUtils()
  9. def get_account(plactform, id=None):
  10. op = f" and id={id} " if id else ''
  11. data = db.quchen_text.getData(f"select text from order_account_text where platform='{plactform}' {op}")
  12. new_data = []
  13. for i in data:
  14. new_data.append(i[0].replace('\n', '').split(","))
  15. return new_data
  16. def get_new_account(plactform):
  17. data = db.quchen_text.getData(
  18. f"select text from order_account_text where platform='{plactform}' and create_time>='{du.get_n_days(-1)}'")
  19. new_data = []
  20. for i in data:
  21. new_data.append(i[0].replace('\n', '').split(","))
  22. return new_data
  23. @DingTalkDecorators("阳光")
  24. def yangguang(start=None, end=None, new=None):
  25. if start:
  26. start = start + ' 00:00:00'
  27. end = end + ' 23:59:59'
  28. else:
  29. start = du.getTodayOrYestoday() + ' 00:00:00'
  30. end = du.get_n_hours_ago(0)
  31. client_id = 10008097
  32. token = '2xa1d55tTPBjeEA8Ho'
  33. accounts = get_account("阳光") if new is None else get_new_account('阳光')
  34. if accounts.__len__() == 0:
  35. return
  36. else:
  37. print(f"阳光账号数:{accounts.__len__()}")
  38. for i in accounts:
  39. stage = i[0]
  40. vip_id = i[1]
  41. print(vip_id)
  42. get_yg_vip_channel(stage, vip_id, client_id, token)
  43. get_yg_data(stage, vip_id, client_id, token, start, end)
  44. x = 1
  45. while True:
  46. a = db.quchen_text.getOne("select count(1) from yangguang_path where update_time is null")
  47. print(f" vip 待处理数量 {a} 正在等待数据回调")
  48. if a == 0:
  49. break
  50. time.sleep(60)
  51. x += 1
  52. if x > 20:
  53. DingTalkUtils.send('阳光订单回调延时20min', '18860455786')
  54. break
  55. for i in accounts:
  56. vip_id = i[1]
  57. stage = i[0]
  58. parse_yg_data(vip_id, stage)
  59. @DingTalkDecorators("花生")
  60. def huasheng(start=None, end=None):
  61. if start is None:
  62. start = end = du.getNow()
  63. executor = ThreadPoolExecutor(max_workers=5)
  64. accounts = get_account("花生")
  65. if len(accounts) == 0:
  66. return
  67. else:
  68. print(f'花生有账号{len(accounts)}个')
  69. for account in accounts:
  70. executor.submit(get_hs_order_task, start, end, account)
  71. executor.shutdown()
  72. @DingTalkDecorators("七悦")
  73. def qiyue(start=None, end=None, new=None):
  74. if start is None:
  75. start = end = du.getNow()
  76. accounts = get_account("七悦") if new is None else get_new_account('七悦')
  77. if len(accounts) == 0:
  78. return
  79. else:
  80. print(f'七悦有账号{len(accounts)}个')
  81. for account in accounts:
  82. get_qiyue_order_task(start, end, account)
  83. @DingTalkDecorators("文鼎")
  84. def wending(start=None, end=None, new=None):
  85. if start is None:
  86. start = end = du.getNow()
  87. accounts = get_account("文鼎") if new is None else get_new_account('文鼎')
  88. if len(accounts) == 0:
  89. return
  90. else:
  91. print(f'文鼎有账号{len(accounts)}个')
  92. for account in accounts:
  93. get_wd_order_task(start, end, account)
  94. @DingTalkDecorators("掌读")
  95. def zhangdu(start=None, end=None, new=None):
  96. if start is None:
  97. start = end = du.getNow()
  98. accounts = get_account("掌读")
  99. if len(accounts) == 0:
  100. return
  101. else:
  102. print(f'掌读有账号{len(accounts)}个')
  103. for account in accounts:
  104. get_zd_order_task(start, end, account)
  105. @DingTalkDecorators("掌中云")
  106. def zhangzhongyun(start=None, end=None, new=None):
  107. if start is None:
  108. start = du.getNow()
  109. end = du.get_n_days(1)
  110. executor = ThreadPoolExecutor(max_workers=5)
  111. accounts = get_account("掌中云")
  112. if len(accounts) == 0:
  113. return
  114. else:
  115. print(f'掌中云有账号{len(accounts)}个')
  116. for account in accounts:
  117. executor.submit(get_zzy_order_task, start, end, account)
  118. executor.shutdown()
  119. @DingTalkDecorators("阅文")
  120. def yueweng(start=None, end=None):
  121. if start is None:
  122. start = end = du.getNow()
  123. executor = ThreadPoolExecutor(max_workers=5)
  124. accounts = get_account("阅文")
  125. if len(accounts) == 0:
  126. return
  127. else:
  128. print(f'阅文有账号{len(accounts)}个')
  129. for account in accounts:
  130. executor.submit(get_yuewen_order_task, start, end, account)
  131. executor.shutdown()
  132. @DingTalkDecorators("七悦有声")
  133. def qiyueyousheng(start=None, end=None):
  134. if start is None:
  135. start = end = du.getNow()
  136. accounts = get_account("七悦有声")
  137. if len(accounts) == 0:
  138. return
  139. else:
  140. print(f'七悦有声有账号{len(accounts)}个')
  141. for account in accounts:
  142. AudioQiyue().get_order(start, end, account)
  143. @DingTalkDecorators("悠书阁")
  144. def youshuge(start=None, end=None):
  145. if start is None:
  146. start = end = du.getNow()
  147. executor = ThreadPoolExecutor(max_workers=5)
  148. accounts = get_account("悠书阁")
  149. if len(accounts) == 0:
  150. return
  151. else:
  152. print(f'悠书阁有账号{len(accounts)}个')
  153. for account in accounts:
  154. executor.submit(get_youshuge_order_task, start, end, account)
  155. executor.shutdown()
  156. def hourly():
  157. # try:
  158. # yangguang()
  159. # except:
  160. # pass
  161. huasheng()
  162. qiyue()
  163. qiyueyousheng()
  164. wending()
  165. zhangdu()
  166. zhangzhongyun()
  167. yueweng()
  168. youshuge()
  169. def daily():
  170. st = du.get_n_days(-10)
  171. et = du.get_n_days(-1)
  172. # try:
  173. # yangguang(st, et)
  174. # except:
  175. # pass
  176. huasheng(st, et)
  177. qiyue(st, et)
  178. qiyueyousheng(st, et)
  179. wending(st, et)
  180. zhangdu(st, et)
  181. zhangzhongyun(st, et)
  182. yueweng(st, et)
  183. youshuge(st, et)
  184. def daily_yg():
  185. st = du.get_n_days(-10)
  186. et = du.get_n_days(-1)
  187. try:
  188. yangguang(st, et)
  189. except:
  190. pass
  191. if __name__ == '__main__':
  192. # a=time.time()
  193. # yangguang()
  194. # print(time.time()-a)
  195. # huasheng('2021-02-24','2021-02-24')
  196. # qiyue()
  197. # wending()
  198. # zhangdu('2020-11-01', '2020-12-20')
  199. # zhangzhongyun('2021-04-01', '2021-04-21')
  200. # youshuge()
  201. # yueweng()
  202. # huasheng()
  203. # qiyue()
  204. # qiyueyousheng()
  205. # wending()
  206. # zhangdu()
  207. zhangzhongyun()