BytedanceMaterialPromotionCount.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Author zhaohailiang
  2. # coding=utf-8
  3. # @Time : 2022/01/19 21:10 下午
  4. # @Site :
  5. # @File : BytedanceMaterialPromotionCount.py
  6. # @Software: PyCharm
  7. # @contact: zhaohailiang@c-top.com.cn
  8. # @Tel 18201631162
  9. import logging
  10. from Apietl.conn.TidbConn import TidbConn
  11. from Apietl.utlis.Utils import Utils
  12. class BytedanceMaterialPromotionCount:
  13. def __init__(self):
  14. self.conn = TidbConn.get_connection()
  15. self.parm = Utils.get_task_args()
  16. self.date_time = self.parm[0]
  17. def taskHandler(self):
  18. try:
  19. sql = """
  20. replace into media_api.bytedance_material_promotion_count
  21. select signature,count(1) from media_api.bytedance_promotion_video_relation report
  22. left join (
  23. select id,signature from media_api.bytedance_file_video_get
  24. where create_time>=date_format(date_sub({date_time},interval 7 day),'%Y-%m-%d')
  25. group by id
  26. )b
  27. on report.video_id=b.id
  28. where signature is not null
  29. group by signature
  30. """.format(date_time=self.date_time)
  31. print(sql)
  32. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  33. self.conn.commit()
  34. TidbConn.conn_close(conn=self.conn)
  35. return 0
  36. except Exception as e:
  37. logging.error(e)
  38. return -1
  39. if __name__ == '__main__':
  40. status = BytedanceMaterialPromotionCount().taskHandler()
  41. if status == 0:
  42. print("作业执行成功")
  43. exit(0)
  44. else:
  45. print("作业执行失败")
  46. exit(-1)