update_cost_data.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from model.DateUtils import DateUtils
  2. from app.api_data.tx_ad_cost import get_cost_older
  3. from app.etl.data_stat_run import do_cost
  4. from app.etl.dm.dm_pitcher_daily_overview import dm_pitcher_daily_overview
  5. from app.etl.dw.dw_channel_daily import dw_channel_daily
  6. from app.etl.dw.dw_pitcher_daily import dw_pitcher_trend
  7. from app.etl.src.src_book_info import src_book_info
  8. from app.etl.dw.dw_book_trend import book_trend
  9. from model.DateUtils import DateUtils
  10. from model.DataBaseUtils import MysqlUtils
  11. from app.api_data.tx_ad_cost.get_cost_older import get_v_data, mysql_insert_daily_vx, get_q_data, mysql_insert_daily_qq
  12. import logging
  13. import time
  14. from logging import handlers
  15. db = MysqlUtils()
  16. du = DateUtils()
  17. def get_data(st, et):
  18. # 1.获取数据
  19. print(st, et)
  20. get_cost_older.run(st, et)
  21. # 同步到ck
  22. do_cost(st, et)
  23. # 2.数据处理
  24. src_book_info() # 书籍卡点信息
  25. # book_annual_expect_profit.run() # 年预期收益
  26. dw_channel_daily()
  27. dw_pitcher_trend()
  28. book_trend()
  29. dm_pitcher_daily_overview()
  30. def get_data_vx(channel, st, et):
  31. # 用于处理单个微信号相关信息
  32. sql = '''select account_id,wechat_account_id,access_token,refresh_token,name,
  33. ifnull(stage,''),ifnull(pitcher,''),ifnull(platform,''),ifnull(book,'') from advertiser_vx
  34. where account_id in (select account_id from channel_by_account_daily
  35. where channel ='{}'
  36. order by dt desc )
  37. '''.format(channel)
  38. token_list_v = db.quchen_text.getData(sql)
  39. print(token_list_v)
  40. time1 = time.time()
  41. li = []
  42. for y in token_list_v:
  43. get_v_data(y, li, st, et)
  44. for _ in li:
  45. print(_)
  46. print('get_daily_vx:' + str(len(li)) + 'cost:' + str(int(time.time() - time1)))
  47. mysql_insert_daily_vx(li)
  48. # do_cost(st, et)
  49. # src_book_info() # 书籍卡点信息
  50. # dw_channel_daily()
  51. # dw_pitcher_trend()
  52. # book_trend()
  53. # dm_pitcher_daily_overview()
  54. def get_data_gdt(channel, st, et):
  55. # 用于处理单个微信号相关信息
  56. sql = '''select account_id,'',access_token,refresh_token,name,
  57. ifnull(stage,''),ifnull(pitcher,''),ifnull(platform,''),ifnull(book,'') from advertiser_qq
  58. where account_id in (select account_id from channel_by_account_daily
  59. where channel ='{}'
  60. order by dt desc )
  61. '''.format(channel)
  62. print(sql)
  63. token_list_v = db.quchen_text.getData(sql)
  64. print(token_list_v)
  65. time1 = time.time()
  66. li = []
  67. for y in token_list_v:
  68. get_q_data(y, li, st, et)
  69. for _ in li:
  70. print(_)
  71. print('get_daily_qq:' + str(len(li)) + 'cost:' + str(int(time.time() - time1)))
  72. mysql_insert_daily_qq(li)
  73. do_cost(st, et)
  74. src_book_info() # 书籍卡点信息
  75. dw_channel_daily()
  76. dw_pitcher_trend()
  77. book_trend()
  78. dm_pitcher_daily_overview()
  79. if __name__ == "__main__":
  80. logging.basicConfig(
  81. handlers=[
  82. logging.handlers.RotatingFileHandler('./cost_data.log',
  83. maxBytes=10 * 1024 * 1024,
  84. backupCount=5,
  85. encoding='utf-8')
  86. , logging.StreamHandler() # 供输出使用
  87. ],
  88. level=logging.INFO,
  89. format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
  90. )
  91. st = du.get_n_days(-20)
  92. et = du.get_n_days(0)
  93. get_data_vx(channel='安宜文海', st=st, et=et)
  94. # get_data(st,et)