12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- # Author zhaohailiang
- # coding=utf-8
- # @Time : 2022/01/19 21:10 下午
- # @Site :
- # @File : BytedanceMaterialPromotionCount.py
- # @Software: PyCharm
- # @contact: zhaohailiang@c-top.com.cn
- # @Tel 18201631162
- import logging
- from Apietl.conn.TidbConn import TidbConn
- from Apietl.utlis.Utils import Utils
- class BytedanceMaterialPromotionCount:
- def __init__(self):
- self.conn = TidbConn.get_connection()
- self.parm = Utils.get_task_args()
- self.date_time = self.parm[0]
- def taskHandler(self):
- try:
- sql = """
- replace into media_api.bytedance_material_promotion_count
- select signature,count(1) from media_api.bytedance_promotion_video_relation report
- left join (
- select id,signature from media_api.bytedance_file_video_get
- where create_time>=date_format(date_sub({date_time},interval 7 day),'%Y-%m-%d')
- group by id
- )b
- on report.video_id=b.id
- where signature is not null
- group by signature
- """.format(date_time=self.date_time)
- print(sql)
- TidbConn.upsert(conn=self.conn, sql_buff=sql)
- self.conn.commit()
- TidbConn.conn_close(conn=self.conn)
- return 0
- except Exception as e:
- logging.error(e)
- return -1
- if __name__ == '__main__':
- status = BytedanceMaterialPromotionCount().taskHandler()
- if status == 0:
- print("作业执行成功")
- exit(0)
- else:
- print("作业执行失败")
- exit(-1)
|