| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | # Author renyupeng# coding=utf-8# @Time    : 2022/8/4 2:35 下午# @Site    : # @File    : AppKuaishouMaterialProjectRelation.py# @Software: PyCharm# @contact: renyupeng@c-top.com.cn# @Tel 1501435553import loggingfrom Apietl.conn.TidbConn import TidbConnclass AppKuaishouMaterialProjectRelation:    def __init__(self):        self.conn = TidbConn.get_connection()    def handler(self):        try:            sql = """select account_id from media_api.kuaishou_video_list                   where stat_date>=date_format(date_sub(now(),interval 3 day),'%Y-%m-%d')            group by account_id"""            account_list = TidbConn.quary(self.conn, sql)            for account_id in account_list:                try:                    sql = """replace into application.kuaishou_project_material_relationselect project_id, signature, date_format(stat_date,'%Y%m%d') as create_time from(select project_id, signature,stat_date,row_number() over (partition by signature order by stat_date desc) as rnfrom (select account_id, signature,stat_date      from media_api.kuaishou_video_list where  account_id ={account_id}       and stat_date>=date_format(date_sub(now(),interval 3 day),'%Y-%m-%d')      and signature is not null      group by stat_date, signature) a         left join     (select account_id, project_id from `jeecg-boot`.ctop_user_allocation where media_id = 2) b     on a.account_id = b.account_idgroup by project_id, signature)twhere rn <=1                    """.format(account_id=account_id[0])                    print(sql)                    TidbConn.upsert(conn=self.conn, sql_buff=sql)                    self.conn.commit()                except Exception as e:                    logging.error(e)                    return -1        except Exception as e:            logging.error(e)            return -1if __name__ == '__main__':    AppKuaishouMaterialProjectRelation().handler()
 |