get_order.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 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. from app.api_data.platform_order.yangguang import yangguang
  9. from multiprocessing import Process
  10. db = MysqlUtils()
  11. def get_account(plactform, id=None):
  12. op = f" and id={id} " if id else ''
  13. data = db.quchen_text.getData(f"select text from order_account_text where platform='{plactform}' {op}")
  14. new_data = []
  15. for i in data:
  16. new_data.append(i[0].replace('\n', '').split(","))
  17. return new_data
  18. def get_new_account(plactform):
  19. data = db.quchen_text.getData(
  20. f"select text from order_account_text where platform='{plactform}' and create_time>='{du.get_n_days(-1)}'")
  21. new_data = []
  22. for i in data:
  23. new_data.append(i[0].replace('\n', '').split(","))
  24. return new_data
  25. @DingTalkDecorators("花生")
  26. def huasheng(start=None, end=None):
  27. if start is None:
  28. start = end = du.getNow()
  29. accounts = get_account("花生")
  30. if len(accounts) == 0:
  31. return
  32. else:
  33. print(f'花生有账号{len(accounts)}个')
  34. # 花生有请求限制 不用多线程
  35. for account in accounts:
  36. get_hs_order_task(start, end, account)
  37. @DingTalkDecorators("七悦")
  38. def qiyue(start=None, end=None, new=None):
  39. if start is None:
  40. start = end = du.getNow()
  41. accounts = get_account("七悦") if new is None else get_new_account('七悦')
  42. if len(accounts) == 0:
  43. return
  44. else:
  45. print(f'七悦有账号{len(accounts)}个')
  46. for account in accounts:
  47. get_qiyue_order_task(start, end, account)
  48. @DingTalkDecorators("文鼎")
  49. def wending(start=None, end=None, new=None):
  50. if start is None:
  51. start = end = du.getNow()
  52. accounts = get_account("文鼎") if new is None else get_new_account('文鼎')
  53. if len(accounts) == 0:
  54. return
  55. else:
  56. print(f'文鼎有账号{len(accounts)}个')
  57. for account in accounts:
  58. get_wd_order_task(start, end, account)
  59. @DingTalkDecorators("掌读")
  60. def zhangdu(start=None, end=None, new=None):
  61. if start is None:
  62. start = end = du.getNow()
  63. accounts = get_account("掌读")
  64. if len(accounts) == 0:
  65. return
  66. else:
  67. print(f'掌读有账号{len(accounts)}个')
  68. for account in accounts:
  69. get_zd_order_task(start, end, account)
  70. @DingTalkDecorators("掌中云")
  71. def zhangzhongyun(start=None, end=None, new=None):
  72. if start is None:
  73. start = du.getNow()
  74. end = du.get_n_days(1)
  75. executor = ThreadPoolExecutor(max_workers=5)
  76. accounts = get_account("掌中云")
  77. if len(accounts) == 0:
  78. return
  79. else:
  80. print(f'掌中云有账号{len(accounts)}个')
  81. for account in accounts:
  82. executor.submit(get_zzy_order_task, start, end, account)
  83. executor.shutdown()
  84. @DingTalkDecorators("阅文")
  85. def yueweng(start=None, end=None):
  86. if start is None:
  87. start = end = du.getNow()
  88. executor = ThreadPoolExecutor(max_workers=5)
  89. accounts = get_account("阅文")
  90. if len(accounts) == 0:
  91. return
  92. else:
  93. print(f'阅文有账号{len(accounts)}个')
  94. for account in accounts:
  95. executor.submit(get_yuewen_order_task, start, end, account)
  96. executor.shutdown()
  97. @DingTalkDecorators("七悦有声")
  98. def qiyueyousheng(start=None, end=None):
  99. if start is None:
  100. start = end = du.getNow()
  101. accounts = get_account("七悦有声")
  102. if len(accounts) == 0:
  103. return
  104. else:
  105. print(f'七悦有声有账号{len(accounts)}个')
  106. for account in accounts:
  107. AudioQiyue().get_order(start, end, account)
  108. @DingTalkDecorators("悠书阁")
  109. def youshuge(start=None, end=None):
  110. if start is None:
  111. start = end = du.getNow()
  112. executor = ThreadPoolExecutor(max_workers=5)
  113. accounts = get_account("悠书阁")
  114. if len(accounts) == 0:
  115. return
  116. else:
  117. print(f'悠书阁有账号{len(accounts)}个')
  118. for account in accounts:
  119. executor.submit(get_youshuge_order_task, start, end, account)
  120. executor.shutdown()
  121. def hourly():
  122. p1 = Process(target=huasheng)
  123. p2 = Process(target=qiyue)
  124. p3 = Process(target=qiyueyousheng)
  125. p4 = Process(target=wending)
  126. p5 = Process(target=zhangdu)
  127. p6 = Process(target=zhangzhongyun)
  128. p7 = Process(target=yueweng)
  129. p8 = Process(target=youshuge)
  130. p9 = Process(target=yangguang)
  131. p1.start()
  132. p1.join()
  133. p2.start()
  134. p2.join()
  135. p3.start()
  136. p3.join()
  137. p4.start()
  138. p4.join()
  139. p5.start()
  140. p5.join()
  141. p6.start()
  142. p6.join()
  143. p7.start()
  144. p7.join()
  145. p8.start()
  146. p8.join()
  147. p9.start()
  148. p9.join()
  149. def daily():
  150. st = du.get_n_days(-10)
  151. et = du.get_n_days(-1)
  152. huasheng(st, et)
  153. qiyue(st, et)
  154. qiyueyousheng(st, et)
  155. wending(st, et)
  156. zhangdu(st, et)
  157. zhangzhongyun(st, et)
  158. yueweng(st, et)
  159. youshuge(st, et)
  160. yangguang(st, et)
  161. def yestoday():
  162. st = et = du.get_n_days(-1)
  163. huasheng(st, et)
  164. qiyue(st, et)
  165. qiyueyousheng(st, et)
  166. wending(st, et)
  167. zhangdu(st, et)
  168. zhangzhongyun(st, et)
  169. yueweng(st, et)
  170. youshuge(st, et)
  171. yangguang(st, et)
  172. if __name__ == '__main__':
  173. # zhangzhongyun()
  174. # yangguang()
  175. # huasheng("2021-04-12",'2021-05-10')
  176. # yueweng("2021-05-11", '2021-05-11')
  177. hourly()