get_cost.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from app.api_data.cost_util import *
  2. from model.DateUtils import DateUtils
  3. from model.DataBaseUtils import MysqlUtils
  4. from concurrent.futures import ThreadPoolExecutor
  5. db = MysqlUtils()
  6. du = DateUtils()
  7. executor = ThreadPoolExecutor(max_workers=50)
  8. def get_accounts(filter=None):
  9. if filter:
  10. if filter=='MP':
  11. return db.quchen_text.getData("select account_id,access_token,name channel from advertiser_vx where (name !='' or name is not null)")
  12. else:
  13. return db.quchen_text.getData("select account_id,access_token,name channel from advertiser_qq where (name !='' or name is not null)")
  14. return db.quchen_text.getData("select account_id,access_token,name channel,'MP' flag from advertiser_vx where (name !='' or name is not null) union "
  15. "select account_id,access_token,name channel,'GDT' flag from advertiser_qq where (name !='' or name is not null)")
  16. """广告"""
  17. def ad():
  18. for account in get_accounts():
  19. executor.submit(get_ad_info, account[0], account[1],account[3])
  20. executor.shutdown()
  21. """广告日消耗"""
  22. def ad_cost_day():
  23. st = '2021-01-01'
  24. et = '2021-03-26'
  25. print(st,et)
  26. for account in get_accounts():
  27. # print(account)
  28. executor.submit(get_ad_cost_day, account[0], account[1],account[3],st,et)
  29. executor.shutdown()
  30. """图片"""
  31. def image():
  32. # 默认拉取前10天创建的图片
  33. for account in get_accounts():
  34. executor.submit(images_info_get, account[0], account[1])
  35. executor.shutdown()
  36. """创意"""
  37. def adcreative():
  38. for account in get_accounts():
  39. executor.submit(get_adcreatives, account[0], account[1],account[3])
  40. executor.shutdown()
  41. def run():
  42. image()
  43. ad()
  44. adcreative()
  45. ad_cost_day()
  46. if __name__ == '__main__':
  47. # MP
  48. # account_id = 18516323
  49. # access_token = '262deda76aec00c2e144e83bd3c0b2a2'
  50. #
  51. # account_id2= 14709511
  52. # access_token2 = 'e87f7b6f860eaeef086ddcc9c3614678'
  53. run()