get_order.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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, new=None):
  59. if start is None:
  60. start = end = du.getTodayOrYestoday()
  61. executor = ThreadPoolExecutor(max_workers=5)
  62. accounts = get_account("花生") if new is None else get_new_account('花生')
  63. if len(accounts) == 0:
  64. return
  65. else:
  66. print(f'花生有账号{len(accounts)}个')
  67. li = []
  68. for account in accounts:
  69. channel_data = get_hs_channel(account)
  70. if not channel_data:
  71. continue
  72. else:
  73. print(f"花生账号:{account[2]} 有channel{len(channel_data)}个")
  74. for merchant in channel_data:
  75. executor.submit(get_huasheng_order_task, start, end, account, merchant, li)
  76. executor.shutdown(True)
  77. save_hs_data(li)
  78. def qiyue(start=None, end=None, new=None):
  79. if start is None:
  80. start = end = du.getNow()
  81. accounts = get_account("七悦") if new is None else get_new_account('七悦')
  82. if len(accounts) == 0:
  83. return
  84. else:
  85. print(f'七悦有账号{len(accounts)}个')
  86. for account in accounts:
  87. get_qiyue_order_task(start, end, account)
  88. def wending(start=None, end=None, new=None):
  89. if start is None:
  90. start = end = du.getNow()
  91. accounts = get_account("文鼎") if new is None else get_new_account('文鼎')
  92. if len(accounts) == 0:
  93. return
  94. else:
  95. print(f'文鼎有账号{len(accounts)}个')
  96. for account in accounts:
  97. get_wd_order_task(start, end, account)
  98. def zhangdu(start=None, end=None, new=None):
  99. if start is None:
  100. start = end = du.getNow()
  101. accounts = get_account("掌读") if new is None else get_new_account('掌读')
  102. if len(accounts) == 0:
  103. return
  104. else:
  105. print(f'掌读有账号{len(accounts)}个')
  106. for account in accounts:
  107. get_zd_order_task(start, end, account)
  108. def zhangzhongyun(start=None, end=None, new=None):
  109. if start is None:
  110. start = du.getNow()
  111. end = du.get_n_days(1)
  112. executor = ThreadPoolExecutor(max_workers=5)
  113. accounts = get_account("掌中云") if new is None else get_new_account('掌中云')
  114. if len(accounts) == 0:
  115. return
  116. else:
  117. print(f'掌中云有账号{len(accounts)}个')
  118. for account in accounts:
  119. executor.submit(get_zzy_order_task, start, end, account)
  120. executor.shutdown()
  121. def yueweng(start=None, end=None):
  122. if start is None:
  123. start = end = du.getNow()
  124. executor = ThreadPoolExecutor(max_workers=5)
  125. accounts = get_account("阅文")
  126. if len(accounts) == 0:
  127. return
  128. else:
  129. print(f'阅文有账号{len(accounts)}个')
  130. for account in accounts:
  131. executor.submit(get_yuewen_order_task, start, end, account)
  132. executor.shutdown()
  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. def youshuge(start=None, end=None):
  144. if start is None:
  145. start = end = du.getNow()
  146. executor = ThreadPoolExecutor(max_workers=5)
  147. accounts = get_account("悠书阁")
  148. if len(accounts) == 0:
  149. return
  150. else:
  151. print(f'悠书阁有账号{len(accounts)}个')
  152. for account in accounts:
  153. executor.submit(get_youshuge_order_task, start, end, account)
  154. executor.shutdown()
  155. def hourly():
  156. # try:
  157. # yangguang()
  158. # except:
  159. # pass
  160. huasheng()
  161. qiyue()
  162. qiyueyousheng()
  163. wending()
  164. zhangdu()
  165. zhangzhongyun()
  166. yueweng()
  167. youshuge()
  168. def daily():
  169. st = du.get_n_days(-10)
  170. et = du.get_n_days(-1)
  171. # try:
  172. # yangguang(st, et)
  173. # except:
  174. # pass
  175. huasheng(st, et)
  176. qiyue(st, et)
  177. qiyueyousheng(st, et)
  178. wending(st, et)
  179. zhangdu(st, et)
  180. zhangzhongyun(st, et)
  181. def daily_yg():
  182. st = du.get_n_days(-10)
  183. et = du.get_n_days(-1)
  184. try:
  185. yangguang(st, et)
  186. except:
  187. pass
  188. if __name__ == '__main__':
  189. # a=time.time()
  190. # yangguang()
  191. # print(time.time()-a)
  192. # huasheng('2021-02-24','2021-02-24')
  193. # qiyue()
  194. # wending()
  195. # zhangdu('2020-11-01', '2020-12-20')
  196. # zhangzhongyun('2021-04-01', '2021-04-21')
  197. youshuge()
  198. # yueweng()