data_stat_run.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #默认做三天的留存数据
  49. for i in du.getDateLists(du.get_n_days(-3), du.getNow()):
  50. dw_daily_channel_cost(i)
  51. main(thedate, thedate)
  52. def daily():
  53. "往前跑10天"
  54. st = du.get_n_days(-10)
  55. et = du.get_n_days(-1)
  56. do_order(st, et)
  57. do_cost(st, et)
  58. if __name__ == '__main__':
  59. logging.basicConfig(
  60. handlers=[
  61. logging.handlers.RotatingFileHandler('./log/data_stat_run.log',
  62. maxBytes=10 * 1024 * 1024,
  63. backupCount=5,
  64. encoding='utf-8')
  65. , logging.StreamHandler() # 供输出使用
  66. ],
  67. level=logging.INFO,
  68. format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
  69. )
  70. main(du.get_n_days(-200), du.getNow())
  71. # hourly()
  72. # daily()
  73. # daily('2021-06-30','2021-07-04')
  74. # do_order('2021-05-30', '2021-06-29')