get_order.py 6.0 KB

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