data_stat_run.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from model.DateUtils import DateUtils
  2. import logging
  3. from model.DingTalkUtils import DingTalkUtils
  4. from app.etl.data_stat_task import *
  5. from app.etl.sync_to_ck_task import *
  6. from app.etl.dm.dm_pitcher_daily_overview import dm_pitcher_daily_overview
  7. from app.etl.dw.dw_channel_daily import dw_channel_daily
  8. from app.etl.dw.dw_pitcher_daily import dw_pitcher_trend
  9. from app.etl.src.src_book_info import src_book_info
  10. from app.etl.dw.dw_book_trend import book_trend
  11. from app.etl.src import book_annual_expect_profit
  12. from logging import handlers
  13. du = DateUtils()
  14. logger = logging.getLogger("")
  15. # logger.setLevel(logging.ERROR)
  16. # logging.getLogger().setLevel(logging.WARNING)
  17. def do_order(st, et):
  18. logging.info('订单数据同步到ck,开始')
  19. for i in du.getDateLists(st, et):
  20. logging.info('订单:' + str(i))
  21. order_sync_ck(i)
  22. logging.info('订单数据同步到ck,结束')
  23. def do_cost(st, et):
  24. logging.info('消耗数据处理,开始')
  25. for i in du.getDateLists(st, et):
  26. logging.info("消耗:" + str(i))
  27. channel_by_account_daily(i)
  28. channel_info_daily(i)
  29. dw_daily_channel_cost(i)
  30. # dw_daily_bytedance_cost(i)
  31. platform_data_sum(i)
  32. logging.info('消耗数据处理,结束')
  33. def main(st, et):
  34. try:
  35. do_order(st, et)
  36. do_cost(st, et)
  37. # src_book_info() # 书籍卡点信息
  38. # book_annual_expect_profit.run() # 年预期收益
  39. dw_channel_daily()
  40. dw_pitcher_trend()
  41. book_trend()
  42. dm_pitcher_daily_overview()
  43. except Exception as e:
  44. logging.error(e)
  45. DingTalkUtils().send("hourlyRun fail!! " + str(e), '15168342316')
  46. def hourly():
  47. thedate = du.getTodayOrYestoday()
  48. main(thedate, thedate)
  49. def daily():
  50. "往前跑10天"
  51. st = du.get_n_days(-10)
  52. et = du.get_n_days(-1)
  53. do_order(st, et)
  54. do_cost(st, et)
  55. if __name__ == '__main__':
  56. logging.basicConfig(
  57. handlers=[
  58. logging.handlers.RotatingFileHandler('./log/data_stat_run.log',
  59. maxBytes=10 * 1024 * 1024,
  60. backupCount=5,
  61. encoding='utf-8')
  62. , logging.StreamHandler() # 供输出使用
  63. ],
  64. level=logging.INFO,
  65. format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
  66. )
  67. hourly()
  68. # daily()
  69. # daily('2021-06-30','2021-07-04')
  70. # do_order('2021-05-30', '2021-06-29')