get_order.py 6.2 KB

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