update_cost_data.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 = '''
  33. select account_id,wechat_account_id,access_token,refresh_token,name,
  34. ifnull(stage,''),ifnull(pitcher,''),ifnull(platform,''),ifnull(book,'') from advertiser_vx
  35. where account_id in (select account_id from channel_by_account_daily
  36. where channel ='{}' and dt in (select max(dt) from channel_by_account_daily cbad)
  37. order by dt desc )
  38. '''.format(channel)
  39. token_list_v = db.quchen_text.getData(sql)
  40. print(token_list_v)
  41. time1 = time.time()
  42. li = []
  43. for y in token_list_v:
  44. get_v_data(y, li, st, et)
  45. for _ in li:
  46. print(_)
  47. print('get_daily_vx:' + str(len(li)) + 'cost:' + str(int(time.time() - time1)))
  48. mysql_insert_daily_vx(li)
  49. # do_cost(st, et)
  50. # src_book_info() # 书籍卡点信息
  51. # dw_channel_daily()
  52. # dw_pitcher_trend()
  53. # book_trend()
  54. # dm_pitcher_daily_overview()
  55. def get_data_gdt(channel, st, et):
  56. # 用于处理单个微信号相关信息
  57. sql = '''select account_id,'',access_token,refresh_token,name,
  58. ifnull(stage,''),ifnull(pitcher,''),ifnull(platform,''),ifnull(book,'') from advertiser_qq
  59. where account_id in (select account_id from channel_by_account_daily
  60. where channel ='{}' and dt in (select max(dt) from channel_by_account_daily cbad)
  61. order by dt desc )
  62. '''.format(channel)
  63. print(sql)
  64. token_list_v = db.quchen_text.getData(sql)
  65. print(token_list_v)
  66. time1 = time.time()
  67. li = []
  68. for y in token_list_v:
  69. get_q_data(y, li, st, et)
  70. for _ in li:
  71. print(_)
  72. print('get_daily_qq:' + str(len(li)) + 'cost:' + str(int(time.time() - time1)))
  73. mysql_insert_daily_qq(li)
  74. do_cost(st, et)
  75. src_book_info() # 书籍卡点信息
  76. dw_channel_daily()
  77. dw_pitcher_trend()
  78. book_trend()
  79. dm_pitcher_daily_overview()
  80. if __name__ == "__main__":
  81. logging.basicConfig(
  82. handlers=[
  83. logging.handlers.RotatingFileHandler('./cost_data.log',
  84. maxBytes=10 * 1024 * 1024,
  85. backupCount=5,
  86. encoding='utf-8')
  87. , logging.StreamHandler() # 供输出使用
  88. ],
  89. level=logging.INFO,
  90. format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
  91. )
  92. st = du.get_n_days(-50)
  93. et = du.get_n_days(-10)
  94. # get_data_vx(channel='落枫文海', st=st, et=et)
  95. # get_data_gdt(channel='落枫文海', st=st, et=et)
  96. # get_data(st,et)
  97. from app.etl import data_stat_task
  98. data_stat_task.dw_daily_channel_cost('2019-07-12')