renyupeng 1 年之前
父节点
当前提交
c490151bb0
共有 2 个文件被更改,包括 119 次插入0 次删除
  1. 52 0
      Apietl/task/BytedanceMaterialPromotionCount.py
  2. 67 0
      Apietl/task/BytedancePromotionVideoRelation.py

+ 52 - 0
Apietl/task/BytedanceMaterialPromotionCount.py

@@ -0,0 +1,52 @@
+# 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)

+ 67 - 0
Apietl/task/BytedancePromotionVideoRelation.py

@@ -0,0 +1,67 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 5:10 下午
+# @Site    :
+# @File    : BytedancePromotionVideoRelation.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+
+import logging
+from math import ceil
+
+from Apietl.kwai_etl.report.ReplaceAccountInfo import ReplaceAccountInfo
+from Apietl.utlis.Logger import Logger
+from Apietl.utlis.Utils import Utils
+from Apietl.conn.TidbConn import TidbConn
+
+
+class BytedancePromotionVideoRelation:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_task_args()
+        self.start_time = self.parm[0]
+
+    def handler(self):
+        try:
+            sql = """select advertiser_id from media_api.bytedance_promotion_list where 
+            promotion_create_time>=date_format(date_sub({start_time},interval 30 day),'%Y-%m-%d')  
+            group by advertiser_id""".format(
+                start_time=self.start_time)
+            account_list = TidbConn.quary(self.conn, sql)
+            for account_id in account_list:
+                sql = """replace into media_api.bytedance_promotion_video_relation
+SELECT promotion_id,
+       replace(trim(substring_index(
+               SUBSTRING_INDEX(replace(replace(JSON_EXTRACT(json_extract(promotion_materials, '$.video_material_list'),
+                                                            '$[*].video_id'), ']', ''), '[', ''), ',', hp.id + 1),
+               ',', - 1)), '"', '') as material_id
+
+FROM media_api.bytedance_promotion_list tp
+         LEFT JOIN test.keyid hp ON hp.id <= length(replace(
+        replace(JSON_EXTRACT(json_extract(promotion_materials, '$.video_material_list'),
+                             '$[*].video_id'), ']', ''), '[', '')) - length(REPLACE(
+        replace(replace(JSON_EXTRACT(json_extract(promotion_materials, '$.video_material_list'),
+                                     '$[*].video_id'), ']', ''), '[', ''), ',', ''))
+where tp.promotion_create_time >= date_format(date_sub({start_time},interval 7 day),'%Y-%m-%d')
+  and json_extract(promotion_materials, '$.video_material_list') is not null
+  and status != 'AUDIT_DENY'
+  and advertiser_id = {account_id}""". \
+                    format(start_time=self.start_time, account_id=account_id[0])
+                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 = BytedancePromotionVideoRelation().handler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)