get_order.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. db = MysqlUtils()
  10. def get_account(plactform, id=None):
  11. op = f" and id={id} " if id else ''
  12. data = db.quchen_text.getData(f"select text from order_account_text where platform='{plactform}' {op}")
  13. new_data = []
  14. for i in data:
  15. new_data.append(i[0].replace('\n', '').split(","))
  16. return new_data
  17. def get_new_account(plactform):
  18. data = db.quchen_text.getData(
  19. f"select text from order_account_text where platform='{plactform}' and create_time>='{du.get_n_days(-1)}'")
  20. new_data = []
  21. for i in data:
  22. new_data.append(i[0].replace('\n', '').split(","))
  23. return new_data
  24. @DingTalkDecorators("花生")
  25. def huasheng(start=None, end=None):
  26. if start is None:
  27. start = end = du.getNow()
  28. executor = ThreadPoolExecutor(max_workers=5)
  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. huasheng()
  123. qiyue()
  124. qiyueyousheng()
  125. wending()
  126. zhangdu()
  127. zhangzhongyun()
  128. yueweng()
  129. youshuge()
  130. yangguang()
  131. def daily():
  132. st = du.get_n_days(-10)
  133. et = du.get_n_days(-1)
  134. huasheng(st, et)
  135. qiyue(st, et)
  136. qiyueyousheng(st, et)
  137. wending(st, et)
  138. zhangdu(st, et)
  139. zhangzhongyun(st, et)
  140. yueweng(st, et)
  141. youshuge(st, et)
  142. yangguang(st, et)
  143. def yestoday():
  144. st = et = du.get_n_days(-1)
  145. huasheng(st, et)
  146. qiyue(st, et)
  147. qiyueyousheng(st, et)
  148. wending(st, et)
  149. zhangdu(st, et)
  150. zhangzhongyun(st, et)
  151. yueweng(st, et)
  152. youshuge(st, et)
  153. yangguang(st, et)
  154. if __name__ == '__main__':
  155. # zhangzhongyun()
  156. # yangguang()
  157. # huasheng("2021-04-12",'2021-05-10')
  158. yueweng("2021-05-11", '2021-05-11')