renyupeng 3 éve
commit
ece79db3a1

+ 14 - 0
Apietl/config.ini

@@ -0,0 +1,14 @@
+[xxl_job]
+xxl_url = 192.168.1.187
+
+[tidb]
+tidb_host = 192.168.1.187
+tidb_port = 4000
+tidb_user = root
+tidb_password = hcst2021
+
+[webhook]
+url = 192.168.0.202
+
+[Log]
+Log_home = /opt/log/

+ 91 - 0
Apietl/conn/TidbConn.py

@@ -0,0 +1,91 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 11:06 上午
+# @Site    : 
+# @File    : TidbConn.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+import logging
+import time
+import pymysql
+from Apietl.constant.ConfConstant import ConfConstant
+
+
+class TidbConn:
+    """
+    Tidb连接管理
+    """
+
+    @staticmethod
+    def get_connection():
+        """
+        获取Tidb连接
+        :return: 连接
+        """
+        return pymysql.connect(host=ConfConstant.TIDB_HOST, user=ConfConstant.TIDB_USER,
+                               passwd=ConfConstant.TIDB_PASSWORD,
+                               port=ConfConstant.TIDB_PORT, charset="utf8")
+
+    @classmethod
+    def _reConn(cls, num=28800, stime=3):  # 重试连接总次数为1天,这里根据实际情况自己设置,如果服务器宕机1天都没发现就......
+        _number = 0
+        _status = True
+        while _status and _number <= num:
+            try:
+                TidbConn.get_connection().ping()  # cping 校验连接是否异常
+                _status = False
+            except:
+                if TidbConn.get_connection():  # 重新连接,成功退出
+                    _status = False
+                    break
+                _number += 1
+                time.sleep(stime)  # 连接不成功,休眠3秒钟,继续循环,知道成功或重试次数结束
+
+    @classmethod
+    def quary(cls, sql):
+        TidbConn._reConn(num=28800, stime=3)
+        mysql_conn = TidbConn.get_connection()
+        cur = mysql_conn.cursor()
+        cur.execute(sql)
+        result = cur.fetchall()
+        return result
+
+    @staticmethod
+    def conn_close(conn: pymysql.connections.Connection):
+        """
+        关闭资源
+        """
+        if conn:
+            try:
+                conn.close()
+            except pymysql.err.Error:
+                pass
+
+    @staticmethod
+    def exec_sql(conn, sql_buff):
+        sql_list = sql_buff.split(";")
+        cur = conn.cursor()
+        for sql in sql_list:
+            if sql.strip():
+                cur.execute(sql)
+        return cur
+
+    @staticmethod
+    def upsert(sql):
+        TidbConn._reConn(num=28800, stime=3)
+        try:
+            TidbConn.exec_sql(TidbConn.get_connection(), sql)
+        except Exception as e:
+            logging.error('失败详细信息:', repr(e))
+        TidbConn.get_connection().commit()
+
+
+if __name__ == '__main__':
+    db = TidbConn.get_connection()
+    cursor = db.cursor()
+    # 执行sql语句
+    sql = "show databases"
+    cursor.execute(sql)
+    result = cursor.fetchall()
+    print("result====", result)
+

+ 39 - 0
Apietl/constant/ConfConstant.py

@@ -0,0 +1,39 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 11:14 上午
+# @Site    : 
+# @File    : ConfConstant.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import os
+from configparser import ConfigParser
+
+dir_name = os.path.dirname(os.path.dirname(__file__))
+
+config_file = dir_name + '/config.ini'
+_cfp = ConfigParser()
+_cfp.read(config_file, encoding='utf-8')
+
+
+class ConfConstant:
+    """
+    配置文件常量类
+    """
+    # tidb 配置信息
+    TIDB_HOST = _cfp.get('tidb', 'tidb_host')
+    TIDB_PORT = _cfp.getint('tidb', 'tidb_port')
+    TIDB_USER = _cfp.get('tidb', 'tidb_user')
+    TIDB_PASSWORD = _cfp.get('tidb', 'tidb_password')
+
+    # xxl-job 配置
+    xxl_url = _cfp.get('xxl_job', 'xxl_url')
+
+    # ### log
+    # # 日志存放路径
+    # LOG_DIR = _cfp.get('log', 'log_dir')
+    # # 日志等级
+    # LOG_LEVEL = _cfp.get('log', 'log_level')
+
+    # webhook配置
+    URL = _cfp.get('webhook', 'url')

+ 681 - 0
Apietl/kwai_etl/report/AccountReport.py

@@ -0,0 +1,681 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 5:10 下午
+# @Site    :
+# @File    : AccountReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+
+import logging
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class AccountReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+
+    def daily_report(self, account_id, start_date, end_date):
+        try:
+            sql = """
+            set sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+            insert into application.kuaishou_account_report_daily_dw
+(account_id, stat_date, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
+ company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
+ play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
+ cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
+ event_outbound_call_ratio, event_ad_watch_times)
+    (
+        select report.advertiser_id as account_id,
+               stat_date,
+               project_id,
+               product_id,
+               sys.advertiser_id,
+               company_id,
+               account_name,
+               project_name,
+               advertiser_name,
+               company_name,
+               sale_id,
+               user_id,
+               org_code,
+               charge,
+               `show`,
+               photo_click,
+               aclick,
+               bclick,
+               photo_click_ratio,
+               play_3s_ratio,
+               action_ratio,
+               impression_1k_cost,
+               photo_click_cost,
+               action_cost,
+               share,
+               comment,
+               `like`,
+               follow,
+               cancel_follow,
+               report,
+               block,
+               negative,
+               submit,
+               download_started,
+               download_completed,
+               activation,
+               event_pay_first_day,
+               event_pay_purchase_amount_first_day,
+               event_pay_first_day_roi,
+               event_pay,
+               event_pay_purchase_amount,
+               event_pay_roi,
+               event_register,
+               event_register_cost,
+               event_register_ratio,
+               event_jin_jian_app,
+               event_jin_jian_app_cost,
+               event_credit_grant_app,
+               event_credit_grant_app_cost,
+               event_credit_grant_app_ratio,
+               event_order_paid,
+               event_order_paid_purchase_amount,
+               event_order_paid_cost,
+               event_next_day_stay,
+               event_next_day_stay_cost,
+               event_next_day_stay_ratio,
+               form_count,
+               form_cost,
+               form_action_ratio,
+               event_jin_jian_landing_page,
+               event_jin_jian_landing_page_cost,
+               event_credit_grant_landing_page,
+               event_credit_grant_landing_page_cost,
+               event_credit_grant_landing_page_ratio,
+               event_valid_clues,
+               event_valid_clues_cost,
+               event_add_wechat,
+               event_add_wechat_cost,
+               event_add_wechat_ratio,
+               event_get_through,
+               event_get_through_cost,
+               event_get_through_ratio,
+               event_app_invoked,
+               event_app_invoked_cost,
+               event_app_invoked_ratio,
+               event_credit_grant_landing_ratio,
+               play_5s_ratio,
+               play_end_ratio,
+               event_new_user_pay,
+               event_new_user_pay_cost,
+               event_new_user_pay_ratio,
+               click_1k_cost,
+               ad_product_cnt,
+               event_goods_view,
+               merchant_reco_fans,
+               event_order_amount_roi,
+               event_goods_view_cost,
+               merchant_reco_fans_cost,
+               event_button_click,
+               event_button_click_cost,
+               event_button_click_ratio,
+               event_order_paid_roi,
+               event_new_user_jinjian_app,
+               event_new_user_jinjian_app_cost,
+               event_new_user_jinjian_app_roi,
+               event_new_user_credit_grant_app,
+               event_new_user_credit_grant_app_cost,
+               event_new_user_credit_grant_app_roi,
+               event_new_user_jinjian_page,
+               event_new_user_jinjian_page_cost,
+               event_new_user_jinjian_page_roi,
+               event_new_user_credit_grant_page,
+               event_new_user_credit_grant_page_cost,
+               event_new_user_credit_grant_page_roi,
+               event_appoint_form,
+               event_appoint_form_cost,
+               event_appoint_form_ratio,
+               event_appoint_jump_click,
+               event_appoint_jump_click_cost,
+               event_appoint_jump_click_ratio,
+               union_event_pay_purchase_amount_7d,
+               union_event_pay_purchase_amount_7d_roi,
+               placement_type,
+               ad_scene,
+               event_order_successed,
+               ad_photo_played_10s_ratio,
+               key_action_cost,
+               event_add_shopping_cart_cost,
+               event_ad_watch_times_ratio,
+               event_outbound_call_cost,
+               event_outbound_call,
+               action_new_ratio,
+               event_watch_app_ad,
+               event_multi_conversion_cost,
+               event_phone_card_activate,
+               ad_photo_played_75percent_ratio,
+               key_action_ratio,
+               event_ad_watch_times_cost,
+               event_add_shopping_cart,
+               key_action,
+               event_multi_conversion,
+               event_wechat_connected,
+               event_dsp_gift_form,
+               event_intention_confirmed,
+               event_phone_get_through,
+               event_multi_conversion_ratio,
+               event_measurement_house,
+               ad_photo_played_2s_ratio,
+               event_outbound_call_ratio,
+               event_ad_watch_times
+        from media_api.kuaishou_account_report_daily report
+                 left join
+             hcst_system.ctop_account_attribution_info sys
+             on report.advertiser_id = sys.account_id
+        where report.stat_date between {start_date} and {end_date}
+        and report.advertiser_id={account_id}
+    )
+on DUPLICATE KEY UPDATE account_id                             =values(account_id),
+                        stat_date                              =values(stat_date),
+                        project_id                             =values(project_id),
+                        product_id                             =values(product_id),
+                        advertiser_id                          =values(advertiser_id),
+                        company_id                             =values(company_id),
+                        account_name                           =values(account_name),
+                        project_name                           =values(project_name),
+                        advertiser_name                        =values(advertiser_name),
+                        company_name                           =values(company_name),
+                        sale_id                                =values(sale_id),
+                        user_id                                =values(user_id),
+                        org_code                               =values(org_code),
+                        charge                                 =values(charge),
+                        `show`                                 =values(`show`),
+                        photo_click                            =values(photo_click),
+                        aclick                                 =values(aclick),
+                        bclick                                 =values(bclick),
+                        photo_click_ratio                      =values(photo_click_ratio),
+                        play_3s_ratio                          =values(play_3s_ratio),
+                        action_ratio                           =values(action_ratio),
+                        impression_1k_cost                     =values(impression_1k_cost),
+                        photo_click_cost                       =values(photo_click_cost),
+                        action_cost                            =values(action_cost),
+                        share                                  =values(share),
+                        comment                                =values(comment),
+                        `like`                                 =values(`like`),
+                        follow                                 =values(follow),
+                        cancel_follow                          =values(cancel_follow),
+                        report                                 =values(report),
+                        block                                  =values(block),
+                        negative                               =values(negative),
+                        submit                                 =values(submit),
+                        download_started                       =values(download_started),
+                        download_completed                     =values(download_completed),
+                        activation                             =values(activation),
+                        event_pay_first_day                    =values(event_pay_first_day),
+                        event_pay_purchase_amount_first_day    =values(event_pay_purchase_amount_first_day),
+                        event_pay_first_day_roi                =values(event_pay_first_day_roi),
+                        event_pay                              =values(event_pay),
+                        event_pay_purchase_amount              =values(event_pay_purchase_amount),
+                        event_pay_roi                          =values(event_pay_roi),
+                        event_register                         =values(event_register),
+                        event_register_cost                    =values(event_register_cost),
+                        event_register_ratio                   =values(event_register_ratio),
+                        event_jin_jian_app                     =values(event_jin_jian_app),
+                        event_jin_jian_app_cost                =values(event_jin_jian_app_cost),
+                        event_credit_grant_app                 =values(event_credit_grant_app),
+                        event_credit_grant_app_cost            =values(event_credit_grant_app_cost),
+                        event_credit_grant_app_ratio           =values(event_credit_grant_app_ratio),
+                        event_order_paid                       =values(event_order_paid),
+                        event_order_paid_purchase_amount       =values(event_order_paid_purchase_amount),
+                        event_order_paid_cost                  =values(event_order_paid_cost),
+                        event_next_day_stay                    =values(event_next_day_stay),
+                        event_next_day_stay_cost               =values(event_next_day_stay_cost),
+                        event_next_day_stay_ratio              =values(event_next_day_stay_ratio),
+                        form_count                             =values(form_count),
+                        form_cost                              =values(form_cost),
+                        form_action_ratio                      =values(form_action_ratio),
+                        event_jin_jian_landing_page            =values(event_jin_jian_landing_page),
+                        event_jin_jian_landing_page_cost       =values(event_jin_jian_landing_page_cost),
+                        event_credit_grant_landing_page        =values(event_credit_grant_landing_page),
+                        event_credit_grant_landing_page_cost   =values(event_credit_grant_landing_page_cost),
+                        event_credit_grant_landing_page_ratio  =values(event_credit_grant_landing_page_ratio),
+                        event_valid_clues                      =values(event_valid_clues),
+                        event_valid_clues_cost                 =values(event_valid_clues_cost),
+                        event_add_wechat                       =values(event_add_wechat),
+                        event_add_wechat_cost                  =values(event_add_wechat_cost),
+                        event_add_wechat_ratio                 =values(event_add_wechat_ratio),
+                        event_get_through                      =values(event_get_through),
+                        event_get_through_cost                 =values(event_get_through_cost),
+                        event_get_through_ratio                =values(event_get_through_ratio),
+                        event_app_invoked                      =values(event_app_invoked),
+                        event_app_invoked_cost                 =values(event_app_invoked_cost),
+                        event_app_invoked_ratio                =values(event_app_invoked_ratio),
+                        event_credit_grant_landing_ratio       =values(event_credit_grant_landing_ratio),
+                        play_5s_ratio                          =values(play_5s_ratio),
+                        play_end_ratio                         =values(play_end_ratio),
+                        event_new_user_pay                     =values(event_new_user_pay),
+                        event_new_user_pay_cost                =values(event_new_user_pay_cost),
+                        event_new_user_pay_ratio               =values(event_new_user_pay_ratio),
+                        click_1k_cost                          =values(click_1k_cost),
+                        ad_product_cnt                         =values(ad_product_cnt),
+                        event_goods_view                       =values(event_goods_view),
+                        merchant_reco_fans                     =values(merchant_reco_fans),
+                        event_order_amount_roi                 =values(event_order_amount_roi),
+                        event_goods_view_cost                  =values(event_goods_view_cost),
+                        merchant_reco_fans_cost                =values(merchant_reco_fans_cost),
+                        event_button_click                     =values(event_button_click),
+                        event_button_click_cost                =values(event_button_click_cost),
+                        event_button_click_ratio               =values(event_button_click_ratio),
+                        event_order_paid_roi                   =values(event_order_paid_roi),
+                        event_new_user_jinjian_app             =values(event_new_user_jinjian_app),
+                        event_new_user_jinjian_app_cost        =values(event_new_user_jinjian_app_cost),
+                        event_new_user_jinjian_app_roi         =values(event_new_user_jinjian_app_roi),
+                        event_new_user_credit_grant_app        =values(event_new_user_credit_grant_app),
+                        event_new_user_credit_grant_app_cost   =values(event_new_user_credit_grant_app_cost),
+                        event_new_user_credit_grant_app_roi    =values(event_new_user_credit_grant_app_roi),
+                        event_new_user_jinjian_page            =values(event_new_user_jinjian_page),
+                        event_new_user_jinjian_page_cost       =values(event_new_user_jinjian_page_cost),
+                        event_new_user_jinjian_page_roi        =values(event_new_user_jinjian_page_roi),
+                        event_new_user_credit_grant_page       =values(event_new_user_credit_grant_page),
+                        event_new_user_credit_grant_page_cost  =values(event_new_user_credit_grant_page_cost),
+                        event_new_user_credit_grant_page_roi   =values(event_new_user_credit_grant_page_roi),
+                        event_appoint_form                     =values(event_appoint_form),
+                        event_appoint_form_cost                =values(event_appoint_form_cost),
+                        event_appoint_form_ratio               =values(event_appoint_form_ratio),
+                        event_appoint_jump_click               =values(event_appoint_jump_click),
+                        event_appoint_jump_click_cost          =values(event_appoint_jump_click_cost),
+                        event_appoint_jump_click_ratio         =values(event_appoint_jump_click_ratio),
+                        union_event_pay_purchase_amount_7d     =values(union_event_pay_purchase_amount_7d),
+                        union_event_pay_purchase_amount_7d_roi =values(union_event_pay_purchase_amount_7d_roi),
+                        placement_type                         =values(placement_type),
+                        ad_scene                               =values(ad_scene),
+                        event_order_successed                  =values(event_order_successed),
+                        ad_photo_played_10s_ratio              =values(ad_photo_played_10s_ratio),
+                        key_action_cost                        =values(key_action_cost),
+                        event_add_shopping_cart_cost           =values(event_add_shopping_cart_cost),
+                        event_ad_watch_times_ratio             =values(event_ad_watch_times_ratio),
+                        event_outbound_call_cost               =values(event_outbound_call_cost),
+                        event_outbound_call                    =values(event_outbound_call),
+                        action_new_ratio                       =values(action_new_ratio),
+                        event_watch_app_ad                     =values(event_watch_app_ad),
+                        event_multi_conversion_cost            =values(event_multi_conversion_cost),
+                        event_phone_card_activate              =values(event_phone_card_activate),
+                        ad_photo_played_75percent_ratio        =values(ad_photo_played_75percent_ratio),
+                        key_action_ratio                       =values(key_action_ratio),
+                        event_ad_watch_times_cost              =values(event_ad_watch_times_cost),
+                        event_add_shopping_cart                =values(event_add_shopping_cart),
+                        key_action                             =values(key_action),
+                        event_multi_conversion                 =values(event_multi_conversion),
+                        event_wechat_connected                 =values(event_wechat_connected),
+                        event_dsp_gift_form                    =values(event_dsp_gift_form),
+                        event_intention_confirmed              =values(event_intention_confirmed),
+                        event_phone_get_through                =values(event_phone_get_through),
+                        event_multi_conversion_ratio           =values(event_multi_conversion_ratio),
+                        event_measurement_house                =values(event_measurement_house),
+                        ad_photo_played_2s_ratio               =values(ad_photo_played_2s_ratio),
+                        event_outbound_call_ratio              =values(event_outbound_call_ratio),
+                        event_ad_watch_times                   =values(event_ad_watch_times);
+            """.format(start_date=start_date, end_date=end_date, account_id=account_id)
+            print(sql)
+            TidbConn.exec_sql(self.conn, sql)
+            self.conn.commit()
+        except Exception as e:
+            logging.error('失败详细信息:', repr(e))
+
+    def hourly_report(self, account_id, start_date, end_date):
+        try:
+            sql = """
+            insert into application.kuaishou_account_report_hourly_dw
+(account_id, stat_date,`hour`, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
+ company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
+ play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
+ cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
+ event_outbound_call_ratio, event_ad_watch_times)
+    (
+        select report.advertiser_id as account_id,
+               stat_date,
+               `hour`,
+               project_id,
+               product_id,
+               sys.advertiser_id,
+               company_id,
+               account_name,
+               project_name,
+               advertiser_name,
+               company_name,
+               sale_id,
+               user_id,
+               org_code,
+               charge,
+               `show`,
+               photo_click,
+               aclick,
+               bclick,
+               photo_click_ratio,
+               play_3s_ratio,
+               action_ratio,
+               impression_1k_cost,
+               photo_click_cost,
+               action_cost,
+               share,
+               comment,
+               `like`,
+               follow,
+               cancel_follow,
+               report,
+               block,
+               negative,
+               submit,
+               download_started,
+               download_completed,
+               activation,
+               event_pay_first_day,
+               event_pay_purchase_amount_first_day,
+               event_pay_first_day_roi,
+               event_pay,
+               event_pay_purchase_amount,
+               event_pay_roi,
+               event_register,
+               event_register_cost,
+               event_register_ratio,
+               event_jin_jian_app,
+               event_jin_jian_app_cost,
+               event_credit_grant_app,
+               event_credit_grant_app_cost,
+               event_credit_grant_app_ratio,
+               event_order_paid,
+               event_order_paid_purchase_amount,
+               event_order_paid_cost,
+               event_next_day_stay,
+               event_next_day_stay_cost,
+               event_next_day_stay_ratio,
+               form_count,
+               form_cost,
+               form_action_ratio,
+               event_jin_jian_landing_page,
+               event_jin_jian_landing_page_cost,
+               event_credit_grant_landing_page,
+               event_credit_grant_landing_page_cost,
+               event_credit_grant_landing_page_ratio,
+               event_valid_clues,
+               event_valid_clues_cost,
+               event_add_wechat,
+               event_add_wechat_cost,
+               event_add_wechat_ratio,
+               event_get_through,
+               event_get_through_cost,
+               event_get_through_ratio,
+               event_app_invoked,
+               event_app_invoked_cost,
+               event_app_invoked_ratio,
+               event_credit_grant_landing_ratio,
+               play_5s_ratio,
+               play_end_ratio,
+               event_new_user_pay,
+               event_new_user_pay_cost,
+               event_new_user_pay_ratio,
+               click_1k_cost,
+               ad_product_cnt,
+               event_goods_view,
+               merchant_reco_fans,
+               event_order_amount_roi,
+               event_goods_view_cost,
+               merchant_reco_fans_cost,
+               event_button_click,
+               event_button_click_cost,
+               event_button_click_ratio,
+               event_order_paid_roi,
+               event_new_user_jinjian_app,
+               event_new_user_jinjian_app_cost,
+               event_new_user_jinjian_app_roi,
+               event_new_user_credit_grant_app,
+               event_new_user_credit_grant_app_cost,
+               event_new_user_credit_grant_app_roi,
+               event_new_user_jinjian_page,
+               event_new_user_jinjian_page_cost,
+               event_new_user_jinjian_page_roi,
+               event_new_user_credit_grant_page,
+               event_new_user_credit_grant_page_cost,
+               event_new_user_credit_grant_page_roi,
+               event_appoint_form,
+               event_appoint_form_cost,
+               event_appoint_form_ratio,
+               event_appoint_jump_click,
+               event_appoint_jump_click_cost,
+               event_appoint_jump_click_ratio,
+               union_event_pay_purchase_amount_7d,
+               union_event_pay_purchase_amount_7d_roi,
+               placement_type,
+               ad_scene,
+               event_order_successed,
+               ad_photo_played_10s_ratio,
+               key_action_cost,
+               event_add_shopping_cart_cost,
+               event_ad_watch_times_ratio,
+               event_outbound_call_cost,
+               event_outbound_call,
+               action_new_ratio,
+               event_watch_app_ad,
+               event_multi_conversion_cost,
+               event_phone_card_activate,
+               ad_photo_played_75percent_ratio,
+               key_action_ratio,
+               event_ad_watch_times_cost,
+               event_add_shopping_cart,
+               key_action,
+               event_multi_conversion,
+               event_wechat_connected,
+               event_dsp_gift_form,
+               event_intention_confirmed,
+               event_phone_get_through,
+               event_multi_conversion_ratio,
+               event_measurement_house,
+               ad_photo_played_2s_ratio,
+               event_outbound_call_ratio,
+               event_ad_watch_times
+        from media_api.kuaishou_account_report_hourly report
+                 left join
+             hcst_system.ctop_account_attribution_info sys
+             on report.advertiser_id = sys.account_id
+        where report.stat_date between {start_date} and {end_date}
+        and  report.advertiser_id={account_id}
+    )
+on DUPLICATE KEY UPDATE account_id                             =values(account_id),
+                        stat_date                              =values(stat_date),
+                        `hour`                                 =values (`hour`),
+                        project_id                             =values(project_id),
+                        product_id                             =values(product_id),
+                        advertiser_id                          =values(advertiser_id),
+                        company_id                             =values(company_id),
+                        account_name                           =values(account_name),
+                        project_name                           =values(project_name),
+                        advertiser_name                        =values(advertiser_name),
+                        company_name                           =values(company_name),
+                        sale_id                                =values(sale_id),
+                        user_id                                =values(user_id),
+                        org_code                               =values(org_code),
+                        charge                                 =values(charge),
+                        `show`                                 =values(`show`),
+                        photo_click                            =values(photo_click),
+                        aclick                                 =values(aclick),
+                        bclick                                 =values(bclick),
+                        photo_click_ratio                      =values(photo_click_ratio),
+                        play_3s_ratio                          =values(play_3s_ratio),
+                        action_ratio                           =values(action_ratio),
+                        impression_1k_cost                     =values(impression_1k_cost),
+                        photo_click_cost                       =values(photo_click_cost),
+                        action_cost                            =values(action_cost),
+                        share                                  =values(share),
+                        comment                                =values(comment),
+                        `like`                                 =values(`like`),
+                        follow                                 =values(follow),
+                        cancel_follow                          =values(cancel_follow),
+                        report                                 =values(report),
+                        block                                  =values(block),
+                        negative                               =values(negative),
+                        submit                                 =values(submit),
+                        download_started                       =values(download_started),
+                        download_completed                     =values(download_completed),
+                        activation                             =values(activation),
+                        event_pay_first_day                    =values(event_pay_first_day),
+                        event_pay_purchase_amount_first_day    =values(event_pay_purchase_amount_first_day),
+                        event_pay_first_day_roi                =values(event_pay_first_day_roi),
+                        event_pay                              =values(event_pay),
+                        event_pay_purchase_amount              =values(event_pay_purchase_amount),
+                        event_pay_roi                          =values(event_pay_roi),
+                        event_register                         =values(event_register),
+                        event_register_cost                    =values(event_register_cost),
+                        event_register_ratio                   =values(event_register_ratio),
+                        event_jin_jian_app                     =values(event_jin_jian_app),
+                        event_jin_jian_app_cost                =values(event_jin_jian_app_cost),
+                        event_credit_grant_app                 =values(event_credit_grant_app),
+                        event_credit_grant_app_cost            =values(event_credit_grant_app_cost),
+                        event_credit_grant_app_ratio           =values(event_credit_grant_app_ratio),
+                        event_order_paid                       =values(event_order_paid),
+                        event_order_paid_purchase_amount       =values(event_order_paid_purchase_amount),
+                        event_order_paid_cost                  =values(event_order_paid_cost),
+                        event_next_day_stay                    =values(event_next_day_stay),
+                        event_next_day_stay_cost               =values(event_next_day_stay_cost),
+                        event_next_day_stay_ratio              =values(event_next_day_stay_ratio),
+                        form_count                             =values(form_count),
+                        form_cost                              =values(form_cost),
+                        form_action_ratio                      =values(form_action_ratio),
+                        event_jin_jian_landing_page            =values(event_jin_jian_landing_page),
+                        event_jin_jian_landing_page_cost       =values(event_jin_jian_landing_page_cost),
+                        event_credit_grant_landing_page        =values(event_credit_grant_landing_page),
+                        event_credit_grant_landing_page_cost   =values(event_credit_grant_landing_page_cost),
+                        event_credit_grant_landing_page_ratio  =values(event_credit_grant_landing_page_ratio),
+                        event_valid_clues                      =values(event_valid_clues),
+                        event_valid_clues_cost                 =values(event_valid_clues_cost),
+                        event_add_wechat                       =values(event_add_wechat),
+                        event_add_wechat_cost                  =values(event_add_wechat_cost),
+                        event_add_wechat_ratio                 =values(event_add_wechat_ratio),
+                        event_get_through                      =values(event_get_through),
+                        event_get_through_cost                 =values(event_get_through_cost),
+                        event_get_through_ratio                =values(event_get_through_ratio),
+                        event_app_invoked                      =values(event_app_invoked),
+                        event_app_invoked_cost                 =values(event_app_invoked_cost),
+                        event_app_invoked_ratio                =values(event_app_invoked_ratio),
+                        event_credit_grant_landing_ratio       =values(event_credit_grant_landing_ratio),
+                        play_5s_ratio                          =values(play_5s_ratio),
+                        play_end_ratio                         =values(play_end_ratio),
+                        event_new_user_pay                     =values(event_new_user_pay),
+                        event_new_user_pay_cost                =values(event_new_user_pay_cost),
+                        event_new_user_pay_ratio               =values(event_new_user_pay_ratio),
+                        click_1k_cost                          =values(click_1k_cost),
+                        ad_product_cnt                         =values(ad_product_cnt),
+                        event_goods_view                       =values(event_goods_view),
+                        merchant_reco_fans                     =values(merchant_reco_fans),
+                        event_order_amount_roi                 =values(event_order_amount_roi),
+                        event_goods_view_cost                  =values(event_goods_view_cost),
+                        merchant_reco_fans_cost                =values(merchant_reco_fans_cost),
+                        event_button_click                     =values(event_button_click),
+                        event_button_click_cost                =values(event_button_click_cost),
+                        event_button_click_ratio               =values(event_button_click_ratio),
+                        event_order_paid_roi                   =values(event_order_paid_roi),
+                        event_new_user_jinjian_app             =values(event_new_user_jinjian_app),
+                        event_new_user_jinjian_app_cost        =values(event_new_user_jinjian_app_cost),
+                        event_new_user_jinjian_app_roi         =values(event_new_user_jinjian_app_roi),
+                        event_new_user_credit_grant_app        =values(event_new_user_credit_grant_app),
+                        event_new_user_credit_grant_app_cost   =values(event_new_user_credit_grant_app_cost),
+                        event_new_user_credit_grant_app_roi    =values(event_new_user_credit_grant_app_roi),
+                        event_new_user_jinjian_page            =values(event_new_user_jinjian_page),
+                        event_new_user_jinjian_page_cost       =values(event_new_user_jinjian_page_cost),
+                        event_new_user_jinjian_page_roi        =values(event_new_user_jinjian_page_roi),
+                        event_new_user_credit_grant_page       =values(event_new_user_credit_grant_page),
+                        event_new_user_credit_grant_page_cost  =values(event_new_user_credit_grant_page_cost),
+                        event_new_user_credit_grant_page_roi   =values(event_new_user_credit_grant_page_roi),
+                        event_appoint_form                     =values(event_appoint_form),
+                        event_appoint_form_cost                =values(event_appoint_form_cost),
+                        event_appoint_form_ratio               =values(event_appoint_form_ratio),
+                        event_appoint_jump_click               =values(event_appoint_jump_click),
+                        event_appoint_jump_click_cost          =values(event_appoint_jump_click_cost),
+                        event_appoint_jump_click_ratio         =values(event_appoint_jump_click_ratio),
+                        union_event_pay_purchase_amount_7d     =values(union_event_pay_purchase_amount_7d),
+                        union_event_pay_purchase_amount_7d_roi =values(union_event_pay_purchase_amount_7d_roi),
+                        placement_type                         =values(placement_type),
+                        ad_scene                               =values(ad_scene),
+                        event_order_successed                  =values(event_order_successed),
+                        ad_photo_played_10s_ratio              =values(ad_photo_played_10s_ratio),
+                        key_action_cost                        =values(key_action_cost),
+                        event_add_shopping_cart_cost           =values(event_add_shopping_cart_cost),
+                        event_ad_watch_times_ratio             =values(event_ad_watch_times_ratio),
+                        event_outbound_call_cost               =values(event_outbound_call_cost),
+                        event_outbound_call                    =values(event_outbound_call),
+                        action_new_ratio                       =values(action_new_ratio),
+                        event_watch_app_ad                     =values(event_watch_app_ad),
+                        event_multi_conversion_cost            =values(event_multi_conversion_cost),
+                        event_phone_card_activate              =values(event_phone_card_activate),
+                        ad_photo_played_75percent_ratio        =values(ad_photo_played_75percent_ratio),
+                        key_action_ratio                       =values(key_action_ratio),
+                        event_ad_watch_times_cost              =values(event_ad_watch_times_cost),
+                        event_add_shopping_cart                =values(event_add_shopping_cart),
+                        key_action                             =values(key_action),
+                        event_multi_conversion                 =values(event_multi_conversion),
+                        event_wechat_connected                 =values(event_wechat_connected),
+                        event_dsp_gift_form                    =values(event_dsp_gift_form),
+                        event_intention_confirmed              =values(event_intention_confirmed),
+                        event_phone_get_through                =values(event_phone_get_through),
+                        event_multi_conversion_ratio           =values(event_multi_conversion_ratio),
+                        event_measurement_house                =values(event_measurement_house),
+                        ad_photo_played_2s_ratio               =values(ad_photo_played_2s_ratio),
+                        event_outbound_call_ratio              =values(event_outbound_call_ratio),
+                        event_ad_watch_times                   =values(event_ad_watch_times);
+            """.format(start_date=start_date, end_date=end_date, account_id=account_id)
+            print(sql)
+            TidbConn.exec_sql(self.conn, sql)
+            self.conn.commit()
+        except Exception as e:
+            logging.error('失败详细信息:', repr(e))
+
+    def handler(self, date_type, account_id, start_date, end_date):
+        if date_type == "daily":
+            self.daily_report(account_id, start_date, end_date)
+        else:
+            self.hourly_report(account_id, start_date, end_date)

+ 222 - 0
Apietl/kwai_etl/report/CampaignDailyReport.py

@@ -0,0 +1,222 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 5:10 下午
+# @Site    :
+# @File    : CampaignDailyReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+
+import logging
+from math import ceil
+from Apietl.utlis.Utils import Utils
+from TidbConn import TidbConn
+
+
+class CampaignDailyReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    def daily_report(self):
+        try:
+            sql = """select count(1) from media_api.kuaishou_campaign_report_daily where 
+            stat_date between {start_time} and {end_time}""".format(
+                start_time=self.start_time, end_time=self.end_time)
+            totalNum = TidbConn.quary(sql)[0][0]
+            pageCount = ceil(totalNum / 5000)
+            for i in range(pageCount):
+                sql = """replace into application.kuaishou_campaign_report_daily_dw
+(account_id, stat_date, campaign_id, campaign_name, project_id, product_id, advertiser_id,
+ company_id, account_name, project_name, advertiser_name, company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio, play_3s_ratio, action_ratio,
+ impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow, cancel_follow, report, block,
+ negative, submit, download_started, download_completed, activation, event_pay_first_day,
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
+ event_outbound_call_ratio, event_ad_watch_times)
+        select report.advertiser_id as account_id,
+               report.stat_date,
+               report.campaign_id,
+               report.campaign_name,
+               sys.project_id,
+               sys.product_id,
+               sys.advertiser_id,
+               sys.company_id,
+               sys.account_name,
+               sys.project_name,
+               sys.advertiser_name,
+               sys.company_name,
+               sys.sale_id,
+               sys.user_id,
+               sys.org_code,
+               report.charge,
+               report.`show`,
+               report.photo_click,
+               report.aclick,
+               report.bclick,
+               report.photo_click_ratio,
+               report.play_3s_ratio,
+               report.action_ratio,
+               report.impression_1k_cost,
+               report.photo_click_cost,
+               report.action_cost,
+               report.share,
+               report.comment,
+               report.`like`,
+               report.follow,
+               report.cancel_follow,
+               report.report,
+               report.block,
+               report.negative,
+               report.submit,
+               report.download_started,
+               report.download_completed,
+               report.activation,
+               report.event_pay_first_day,
+               report.event_pay_purchase_amount_first_day,
+               report.event_pay_first_day_roi,
+               report.event_pay,
+               report.event_pay_purchase_amount,
+               report.event_pay_roi,
+               report.event_register,
+               report.event_register_cost,
+               report.event_register_ratio,
+               report.event_jin_jian_app,
+               report.event_jin_jian_app_cost,
+               report.event_credit_grant_app,
+               report.event_credit_grant_app_cost,
+               report.event_credit_grant_app_ratio,
+               report.event_order_paid,
+               report.event_order_paid_purchase_amount,
+               report.event_order_paid_cost,
+               report.event_next_day_stay,
+               report.event_next_day_stay_cost,
+               report.event_next_day_stay_ratio,
+               report.form_count,
+               report.form_cost,
+               report.form_action_ratio,
+               report.event_jin_jian_landing_page,
+               report.event_jin_jian_landing_page_cost,
+               report.event_credit_grant_landing_page,
+               report.event_credit_grant_landing_page_cost,
+               report.event_credit_grant_landing_page_ratio,
+               report.event_valid_clues,
+               report.event_valid_clues_cost,
+               report.event_add_wechat,
+               report.event_add_wechat_cost,
+               report.event_add_wechat_ratio,
+               report.event_get_through,
+               report.event_get_through_cost,
+               report.event_get_through_ratio,
+               report.event_app_invoked,
+               report.event_app_invoked_cost,
+               report.event_app_invoked_ratio,
+               report.event_credit_grant_landing_ratio,
+               report.play_5s_ratio,
+               report.play_end_ratio,
+               report.event_new_user_pay,
+               report.event_new_user_pay_cost,
+               report.event_new_user_pay_ratio,
+               report.click_1k_cost,
+               report.ad_product_cnt,
+               report.event_goods_view,
+               report.merchant_reco_fans,
+               report.event_order_amount_roi,
+               report.event_goods_view_cost,
+               report.merchant_reco_fans_cost,
+               report.event_button_click,
+               report.event_button_click_cost,
+               report.event_button_click_ratio,
+               report.event_order_paid_roi,
+               report.event_new_user_jinjian_app,
+               report.event_new_user_jinjian_app_cost,
+               report.event_new_user_jinjian_app_roi,
+               report.event_new_user_credit_grant_app,
+               report.event_new_user_credit_grant_app_cost,
+               report.event_new_user_credit_grant_app_roi,
+               report.event_new_user_jinjian_page,
+               report.event_new_user_jinjian_page_cost,
+               report.event_new_user_jinjian_page_roi,
+               report.event_new_user_credit_grant_page,
+               report.event_new_user_credit_grant_page_cost,
+               report.event_new_user_credit_grant_page_roi,
+               report.event_appoint_form,
+               report.event_appoint_form_cost,
+               report.event_appoint_form_ratio,
+               report.event_appoint_jump_click,
+               report.event_appoint_jump_click_cost,
+               report.event_appoint_jump_click_ratio,
+               report.union_event_pay_purchase_amount_7d,
+               report.union_event_pay_purchase_amount_7d_roi,
+               report.placement_type,
+               report.ad_scene,
+               report.event_order_successed,
+               report.ad_photo_played_10s_ratio,
+               report.key_action_cost,
+               report.event_add_shopping_cart_cost,
+               report.event_ad_watch_times_ratio,
+               report.event_outbound_call_cost,
+               report.event_outbound_call,
+               report.action_new_ratio,
+               report.event_watch_app_ad,
+               report.event_multi_conversion_cost,
+               report.event_phone_card_activate,
+               report.ad_photo_played_75percent_ratio,
+               report.key_action_ratio,
+               report.event_ad_watch_times_cost,
+               report.event_add_shopping_cart,
+               report.key_action,
+               report.event_multi_conversion,
+               report.event_wechat_connected,
+               report.event_dsp_gift_form,
+               report.event_intention_confirmed,
+               report.event_phone_get_through,
+               report.event_multi_conversion_ratio,
+               report.event_measurement_house,
+               report.ad_photo_played_2s_ratio,
+               report.event_outbound_call_ratio,
+               report.event_ad_watch_times
+        from media_api.kuaishou_campaign_report_daily report
+                 left join
+             hcst_system.ctop_account_attribution_info sys
+             on report.advertiser_id = sys.account_id
+        where report.stat_date between {start_time} and {end_time} order by campaign_id,stat_date limit {num},5000""". \
+                    format(start_time=self.start_time, end_time=self.end_time, num=i * 5000)
+                TidbConn.exec_sql(self.conn, sql)
+                self.conn.commit()
+                return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = CampaignDailyReport().daily_report()
+
+    if status == 0:
+        logging.info("作业执行成功")
+    else:
+        logging.info("作业执行失败")

+ 222 - 0
Apietl/kwai_etl/report/CampaignHourlyReport.py

@@ -0,0 +1,222 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 5:10 下午
+# @Site    :
+# @File    : CampaignHourlyReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+
+import logging
+from math import ceil
+from Apietl.utlis.Utils import Utils
+from TidbConn import TidbConn
+
+
+class CampaignHourlyReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    def hourly_report(self):
+        try:
+            sql = """select count(1) from media_api.kuaishou_campaign_report_hourly where 
+            stat_date between {start_time} and {end_time}""".format(
+                start_time=self.start_time, end_time=self.end_time)
+            totalNum = TidbConn.quary(sql)[0][0]
+            pageCount = ceil(totalNum / 5000)
+            for i in range(pageCount):
+                sql = """replace into application.kuaishou_campaign_report_hourly_dw
+(account_id, stat_date,`hour`, campaign_id, campaign_name, project_id, product_id, advertiser_id,
+ company_id, account_name, project_name, advertiser_name, company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio, play_3s_ratio, action_ratio,
+ impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow, cancel_follow, report, block,
+ negative, submit, download_started, download_completed, activation, event_pay_first_day,
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
+ event_outbound_call_ratio, event_ad_watch_times)
+        select report.advertiser_id as account_id,
+               report.stat_date,
+               report.hour,
+               report.campaign_id,
+               report.campaign_name,
+               sys.project_id,
+               sys.product_id,
+               sys.advertiser_id,
+               sys.company_id,
+               sys.account_name,
+               sys.project_name,
+               sys.advertiser_name,
+               sys.company_name,
+               sys.sale_id,
+               sys.user_id,
+               sys.org_code,
+               report.charge,
+               report.`show`,
+               report.photo_click,
+               report.aclick,
+               report.bclick,
+               report.photo_click_ratio,
+               report.play_3s_ratio,
+               report.action_ratio,
+               report.impression_1k_cost,
+               report.photo_click_cost,
+               report.action_cost,
+               report.share,
+               report.comment,
+               report.`like`,
+               report.follow,
+               report.cancel_follow,
+               report.report,
+               report.block,
+               report.negative,
+               report.submit,
+               report.download_started,
+               report.download_completed,
+               report.activation,
+               report.event_pay_first_day,
+               report.event_pay_purchase_amount_first_day,
+               report.event_pay_first_day_roi,
+               report.event_pay,
+               report.event_pay_purchase_amount,
+               report.event_pay_roi,
+               report.event_register,
+               report.event_register_cost,
+               report.event_register_ratio,
+               report.event_jin_jian_app,
+               report.event_jin_jian_app_cost,
+               report.event_credit_grant_app,
+               report.event_credit_grant_app_cost,
+               report.event_credit_grant_app_ratio,
+               report.event_order_paid,
+               report.event_order_paid_purchase_amount,
+               report.event_order_paid_cost,
+               report.event_next_day_stay,
+               report.event_next_day_stay_cost,
+               report.event_next_day_stay_ratio,
+               report.form_count,
+               report.form_cost,
+               report.form_action_ratio,
+               report.event_jin_jian_landing_page,
+               report.event_jin_jian_landing_page_cost,
+               report.event_credit_grant_landing_page,
+               report.event_credit_grant_landing_page_cost,
+               report.event_credit_grant_landing_page_ratio,
+               report.event_valid_clues,
+               report.event_valid_clues_cost,
+               report.event_add_wechat,
+               report.event_add_wechat_cost,
+               report.event_add_wechat_ratio,
+               report.event_get_through,
+               report.event_get_through_cost,
+               report.event_get_through_ratio,
+               report.event_app_invoked,
+               report.event_app_invoked_cost,
+               report.event_app_invoked_ratio,
+               report.event_credit_grant_landing_ratio,
+               report.play_5s_ratio,
+               report.play_end_ratio,
+               report.event_new_user_pay,
+               report.event_new_user_pay_cost,
+               report.event_new_user_pay_ratio,
+               report.click_1k_cost,
+               report.ad_product_cnt,
+               report.event_goods_view,
+               report.merchant_reco_fans,
+               report.event_order_amount_roi,
+               report.event_goods_view_cost,
+               report.merchant_reco_fans_cost,
+               report.event_button_click,
+               report.event_button_click_cost,
+               report.event_button_click_ratio,
+               report.event_order_paid_roi,
+               report.event_new_user_jinjian_app,
+               report.event_new_user_jinjian_app_cost,
+               report.event_new_user_jinjian_app_roi,
+               report.event_new_user_credit_grant_app,
+               report.event_new_user_credit_grant_app_cost,
+               report.event_new_user_credit_grant_app_roi,
+               report.event_new_user_jinjian_page,
+               report.event_new_user_jinjian_page_cost,
+               report.event_new_user_jinjian_page_roi,
+               report.event_new_user_credit_grant_page,
+               report.event_new_user_credit_grant_page_cost,
+               report.event_new_user_credit_grant_page_roi,
+               report.event_appoint_form,
+               report.event_appoint_form_cost,
+               report.event_appoint_form_ratio,
+               report.event_appoint_jump_click,
+               report.event_appoint_jump_click_cost,
+               report.event_appoint_jump_click_ratio,
+               report.union_event_pay_purchase_amount_7d,
+               report.union_event_pay_purchase_amount_7d_roi,
+               report.placement_type,
+               report.ad_scene,
+               report.event_order_successed,
+               report.ad_photo_played_10s_ratio,
+               report.key_action_cost,
+               report.event_add_shopping_cart_cost,
+               report.event_ad_watch_times_ratio,
+               report.event_outbound_call_cost,
+               report.event_outbound_call,
+               report.action_new_ratio,
+               report.event_watch_app_ad,
+               report.event_multi_conversion_cost,
+               report.event_phone_card_activate,
+               report.ad_photo_played_75percent_ratio,
+               report.key_action_ratio,
+               report.event_ad_watch_times_cost,
+               report.event_add_shopping_cart,
+               report.key_action,
+               report.event_multi_conversion,
+               report.event_wechat_connected,
+               report.event_dsp_gift_form,
+               report.event_intention_confirmed,
+               report.event_phone_get_through,
+               report.event_multi_conversion_ratio,
+               report.event_measurement_house,
+               report.ad_photo_played_2s_ratio,
+               report.event_outbound_call_ratio,
+               report.event_ad_watch_times
+        from media_api.kuaishou_campaign_report_hourly report
+                 left join
+             hcst_system.ctop_account_attribution_info sys
+             on report.advertiser_id = sys.account_id
+        where report.stat_date between {start_time} and {end_time} order by campaign_id,stat_date,`hour` limit {num},5000""". \
+                    format(start_time=self.start_time, end_time=self.end_time, num=i * 5000)
+                TidbConn.exec_sql(self.conn, sql)
+                self.conn.commit()
+                return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = CampaignHourlyReport().hourly_report()
+    if status == 0:
+        logging.info("作业执行成功")
+    else:
+        logging.info("作业执行失败")

+ 288 - 0
Apietl/kwai_etl/report/MateirialVideoDailyReport.py

@@ -0,0 +1,288 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 5:10 下午
+# @Site    :
+# @File    : MateirialVideoDailyReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+
+import logging
+from math import ceil
+from Apietl.utlis.Utils import Utils
+from TidbConn import TidbConn
+
+
+class MateirialVideoDailyReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    def daily_report(self):
+        try:
+            sql = """select count(1) from media_api.kuaishou_material_video_report_daily where 
+            stat_date between {start_time} and {end_time}""".format(
+                start_time=self.start_time, end_time=self.end_time)
+            totalNum = TidbConn.quary(sql)[0][0]
+            pageCount = ceil(totalNum / 5000)
+            for i in range(pageCount):
+                sql = """replace into application.kuaishou_material_video_report_daily_dw
+(account_id, project_id, product_id, advertiser_id,
+ company_id, account_name, project_name,
+ advertiser_name, company_name, sale_id, user_id,
+ clip_id, shot_id, plan_id, leader_id, org_code,
+ photo_url, photo_id, cover_url, image_token,
+ photo_caption, stat_date, charge, `show`, photo_click,
+ aclick, bclick, photo_click_ratio, play_3s_ratio,
+ action_ratio, impression_1k_cost, photo_click_cost,
+ action_cost, share, comment, `like`, follow,
+ cancel_follow, report, block, negative, submit,
+ download_started, download_completed, activation,
+ event_pay_first_day,
+ event_pay_purchase_amount_first_day,
+ event_pay_first_day_roi, event_pay,
+ event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost,
+ event_register_ratio, event_jin_jian_app,
+ event_jin_jian_app_cost, event_credit_grant_app,
+ event_credit_grant_app_cost,
+ event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount,
+ event_order_paid_cost, event_next_day_stay,
+ event_next_day_stay_cost, event_next_day_stay_ratio,
+ form_count, form_cost, form_action_ratio,
+ event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost,
+ event_credit_grant_landing_page,
+ event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio,
+ event_valid_clues, event_valid_clues_cost,
+ event_add_wechat, event_add_wechat_cost,
+ event_add_wechat_ratio, event_get_through,
+ event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost,
+ event_app_invoked_ratio,
+ event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay,
+ event_new_user_pay_cost, event_new_user_pay_ratio,
+ click_1k_cost, ad_product_cnt, event_goods_view,
+ merchant_reco_fans, event_order_amount_roi,
+ event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost,
+ event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app,
+ event_new_user_jinjian_app_cost,
+ event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app,
+ event_new_user_credit_grant_app_cost,
+ event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page,
+ event_new_user_jinjian_page_cost,
+ event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page,
+ event_new_user_credit_grant_page_cost,
+ event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost,
+ event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost,
+ event_appoint_jump_click_ratio,
+ union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type,
+ ad_scene, event_order_successed,
+ ad_photo_played_10s_ratio, key_action_cost,
+ event_add_shopping_cart_cost,
+ event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio,
+ event_watch_app_ad, event_multi_conversion_cost,
+ event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio,
+ event_ad_watch_times_cost, event_add_shopping_cart,
+ key_action, event_multi_conversion,
+ event_wechat_connected, event_dsp_gift_form,
+ event_intention_confirmed, event_phone_get_through,
+ event_multi_conversion_ratio, event_measurement_house,
+ ad_photo_played_2s_ratio, event_outbound_call_ratio,
+ event_ad_watch_times,
+ signature)
+select report.advertiser_id as account_id,
+       project_id,
+       product_id,
+       sys.advertiser_id,
+       company_id,
+       account_name,
+       project_name,
+       advertiser_name,
+       company_name,
+       sale_id,
+       user_id,
+       clip_id,
+       shot_id,
+       plan_id,
+       leader_id,
+       org_code,
+        report.photo_url,
+       report.photo_id,
+        report.cover_url,
+        report.image_token,
+        report.photo_caption,
+       stat_date,
+       charge,
+       `show`,
+       photo_click,
+       aclick,
+       bclick,
+       photo_click_ratio,
+       play_3s_ratio,
+       action_ratio,
+       impression_1k_cost,
+       photo_click_cost,
+       action_cost,
+       share,
+       comment,
+       `like`,
+       follow,
+       cancel_follow,
+       report,
+       block,
+       negative,
+       submit,
+       download_started,
+       download_completed,
+       activation,
+       event_pay_first_day,
+       event_pay_purchase_amount_first_day,
+       event_pay_first_day_roi,
+       event_pay,
+       event_pay_purchase_amount,
+       event_pay_roi,
+       event_register,
+       event_register_cost,
+       event_register_ratio,
+       event_jin_jian_app,
+       event_jin_jian_app_cost,
+       event_credit_grant_app,
+       event_credit_grant_app_cost,
+       event_credit_grant_app_ratio,
+       event_order_paid,
+       event_order_paid_purchase_amount,
+       event_order_paid_cost,
+       event_next_day_stay,
+       event_next_day_stay_cost,
+       event_next_day_stay_ratio,
+       form_count,
+       form_cost,
+       form_action_ratio,
+       event_jin_jian_landing_page,
+       event_jin_jian_landing_page_cost,
+       event_credit_grant_landing_page,
+       event_credit_grant_landing_page_cost,
+       event_credit_grant_landing_page_ratio,
+       event_valid_clues,
+       event_valid_clues_cost,
+       event_add_wechat,
+       event_add_wechat_cost,
+       event_add_wechat_ratio,
+       event_get_through,
+       event_get_through_cost,
+       event_get_through_ratio,
+       event_app_invoked,
+       event_app_invoked_cost,
+       event_app_invoked_ratio,
+       event_credit_grant_landing_ratio,
+       play_5s_ratio,
+       play_end_ratio,
+       event_new_user_pay,
+       event_new_user_pay_cost,
+       event_new_user_pay_ratio,
+       click_1k_cost,
+       ad_product_cnt,
+       event_goods_view,
+       merchant_reco_fans,
+       event_order_amount_roi,
+       event_goods_view_cost,
+       merchant_reco_fans_cost,
+       event_button_click,
+       event_button_click_cost,
+       event_button_click_ratio,
+       event_order_paid_roi,
+       event_new_user_jinjian_app,
+       event_new_user_jinjian_app_cost,
+       event_new_user_jinjian_app_roi,
+       event_new_user_credit_grant_app,
+       event_new_user_credit_grant_app_cost,
+       event_new_user_credit_grant_app_roi,
+       event_new_user_jinjian_page,
+       event_new_user_jinjian_page_cost,
+       event_new_user_jinjian_page_roi,
+       event_new_user_credit_grant_page,
+       event_new_user_credit_grant_page_cost,
+       event_new_user_credit_grant_page_roi,
+       event_appoint_form,
+       event_appoint_form_cost,
+       event_appoint_form_ratio,
+       event_appoint_jump_click,
+       event_appoint_jump_click_cost,
+       event_appoint_jump_click_ratio,
+       union_event_pay_purchase_amount_7d,
+       union_event_pay_purchase_amount_7d_roi,
+       placement_type,
+       ad_scene,
+       event_order_successed,
+       ad_photo_played_10s_ratio,
+       key_action_cost,
+       event_add_shopping_cart_cost,
+       event_ad_watch_times_ratio,
+       event_outbound_call_cost,
+       event_outbound_call,
+       action_new_ratio,
+       event_watch_app_ad,
+       event_multi_conversion_cost,
+       event_phone_card_activate,
+       ad_photo_played_75percent_ratio,
+       key_action_ratio,
+       event_ad_watch_times_cost,
+       event_add_shopping_cart,
+       key_action,
+       event_multi_conversion,
+       event_wechat_connected,
+       event_dsp_gift_form,
+       event_intention_confirmed,
+       event_phone_get_through,
+       event_multi_conversion_ratio,
+       event_measurement_house,
+       ad_photo_played_2s_ratio,
+       event_outbound_call_ratio,
+       event_ad_watch_times,
+       video.signature,
+       sys.channel_type ,
+       sys.clip_name,
+       sys.shot_name,
+       sys.plan_name,
+       sys.leader_name,
+       sys.video_name,
+       sys.channel_name,
+       sys.clip_company_id
+from media_api.kuaishou_material_video_report_daily report
+    left join media_api.kuaishou_video_list video
+    on report.advertiser_id=video.advertiser_id and report.photo_id=video.photo_id
+         left join
+     hcst_system.ctop_material_attribution_info sys
+     on report.advertiser_id = sys.account_id
+ where report.stat_date between {start_time} and {end_time} and  report.photo_id!=0
+  order by advertiser_id,photo_id ,stat_date limit {num},5000""".format(
+                    start_time=self.start_time, end_time=self.end_time, num=i * 5000)
+                TidbConn.exec_sql(self.conn, sql)
+                self.conn.commit()
+                return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = MateirialVideoDailyReport().daily_report()
+    if status == 0:
+        logging.info("作业执行成功")
+    else:
+        logging.info("作业执行失败")

+ 289 - 0
Apietl/kwai_etl/report/MateirialVideoHourlyReport.py

@@ -0,0 +1,289 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 5:10 下午
+# @Site    :
+# @File    : MateirialVideoHourlyReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+
+import logging
+from math import ceil
+from Apietl.utlis.Utils import Utils
+from TidbConn import TidbConn
+
+
+class MateirialVideoHourlyReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    def hourly_report(self):
+        try:
+            sql = """select count(1) from media_api.kuaishou_material_video_report_hourly where 
+            stat_date between {start_time} and {end_time}""".format(
+                start_time=self.start_time, end_time=self.end_time)
+            totalNum = TidbConn.quary(sql)[0][0]
+            pageCount = ceil(totalNum / 5000)
+            for i in range(pageCount):
+                sql = """replace into application.kuaishou_material_video_report_daily_dw
+(account_id, project_id, product_id, advertiser_id,
+ company_id, account_name, project_name,
+ advertiser_name, company_name, sale_id, user_id,
+ clip_id, shot_id, plan_id, leader_id, org_code,
+ photo_url, photo_id, cover_url, image_token,
+ photo_caption, stat_date, charge, `show`, photo_click,
+ aclick, bclick, photo_click_ratio, play_3s_ratio,
+ action_ratio, impression_1k_cost, photo_click_cost,
+ action_cost, share, comment, `like`, follow,
+ cancel_follow, report, block, negative, submit,
+ download_started, download_completed, activation,
+ event_pay_first_day,
+ event_pay_purchase_amount_first_day,
+ event_pay_first_day_roi, event_pay,
+ event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost,
+ event_register_ratio, event_jin_jian_app,
+ event_jin_jian_app_cost, event_credit_grant_app,
+ event_credit_grant_app_cost,
+ event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount,
+ event_order_paid_cost, event_next_day_stay,
+ event_next_day_stay_cost, event_next_day_stay_ratio,
+ form_count, form_cost, form_action_ratio,
+ event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost,
+ event_credit_grant_landing_page,
+ event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio,
+ event_valid_clues, event_valid_clues_cost,
+ event_add_wechat, event_add_wechat_cost,
+ event_add_wechat_ratio, event_get_through,
+ event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost,
+ event_app_invoked_ratio,
+ event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay,
+ event_new_user_pay_cost, event_new_user_pay_ratio,
+ click_1k_cost, ad_product_cnt, event_goods_view,
+ merchant_reco_fans, event_order_amount_roi,
+ event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost,
+ event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app,
+ event_new_user_jinjian_app_cost,
+ event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app,
+ event_new_user_credit_grant_app_cost,
+ event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page,
+ event_new_user_jinjian_page_cost,
+ event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page,
+ event_new_user_credit_grant_page_cost,
+ event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost,
+ event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost,
+ event_appoint_jump_click_ratio,
+ union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type,
+ ad_scene, event_order_successed,
+ ad_photo_played_10s_ratio, key_action_cost,
+ event_add_shopping_cart_cost,
+ event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio,
+ event_watch_app_ad, event_multi_conversion_cost,
+ event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio,
+ event_ad_watch_times_cost, event_add_shopping_cart,
+ key_action, event_multi_conversion,
+ event_wechat_connected, event_dsp_gift_form,
+ event_intention_confirmed, event_phone_get_through,
+ event_multi_conversion_ratio, event_measurement_house,
+ ad_photo_played_2s_ratio, event_outbound_call_ratio,
+ event_ad_watch_times,
+ signature)
+select report.advertiser_id as account_id,
+       project_id,
+       product_id,
+       sys.advertiser_id,
+       company_id,
+       account_name,
+       project_name,
+       advertiser_name,
+       company_name,
+       sale_id,
+       user_id,
+       clip_id,
+       shot_id,
+       plan_id,
+       leader_id,
+       org_code,
+        report.photo_url,
+       report.photo_id,
+        report.cover_url,
+        report.image_token,
+        report.photo_caption,
+       stat_date,
+       charge,
+       `show`,
+       photo_click,
+       aclick,
+       bclick,
+       photo_click_ratio,
+       play_3s_ratio,
+       action_ratio,
+       impression_1k_cost,
+       photo_click_cost,
+       action_cost,
+       share,
+       comment,
+       `like`,
+       follow,
+       cancel_follow,
+       report,
+       block,
+       negative,
+       submit,
+       download_started,
+       download_completed,
+       activation,
+       event_pay_first_day,
+       event_pay_purchase_amount_first_day,
+       event_pay_first_day_roi,
+       event_pay,
+       event_pay_purchase_amount,
+       event_pay_roi,
+       event_register,
+       event_register_cost,
+       event_register_ratio,
+       event_jin_jian_app,
+       event_jin_jian_app_cost,
+       event_credit_grant_app,
+       event_credit_grant_app_cost,
+       event_credit_grant_app_ratio,
+       event_order_paid,
+       event_order_paid_purchase_amount,
+       event_order_paid_cost,
+       event_next_day_stay,
+       event_next_day_stay_cost,
+       event_next_day_stay_ratio,
+       form_count,
+       form_cost,
+       form_action_ratio,
+       event_jin_jian_landing_page,
+       event_jin_jian_landing_page_cost,
+       event_credit_grant_landing_page,
+       event_credit_grant_landing_page_cost,
+       event_credit_grant_landing_page_ratio,
+       event_valid_clues,
+       event_valid_clues_cost,
+       event_add_wechat,
+       event_add_wechat_cost,
+       event_add_wechat_ratio,
+       event_get_through,
+       event_get_through_cost,
+       event_get_through_ratio,
+       event_app_invoked,
+       event_app_invoked_cost,
+       event_app_invoked_ratio,
+       event_credit_grant_landing_ratio,
+       play_5s_ratio,
+       play_end_ratio,
+       event_new_user_pay,
+       event_new_user_pay_cost,
+       event_new_user_pay_ratio,
+       click_1k_cost,
+       ad_product_cnt,
+       event_goods_view,
+       merchant_reco_fans,
+       event_order_amount_roi,
+       event_goods_view_cost,
+       merchant_reco_fans_cost,
+       event_button_click,
+       event_button_click_cost,
+       event_button_click_ratio,
+       event_order_paid_roi,
+       event_new_user_jinjian_app,
+       event_new_user_jinjian_app_cost,
+       event_new_user_jinjian_app_roi,
+       event_new_user_credit_grant_app,
+       event_new_user_credit_grant_app_cost,
+       event_new_user_credit_grant_app_roi,
+       event_new_user_jinjian_page,
+       event_new_user_jinjian_page_cost,
+       event_new_user_jinjian_page_roi,
+       event_new_user_credit_grant_page,
+       event_new_user_credit_grant_page_cost,
+       event_new_user_credit_grant_page_roi,
+       event_appoint_form,
+       event_appoint_form_cost,
+       event_appoint_form_ratio,
+       event_appoint_jump_click,
+       event_appoint_jump_click_cost,
+       event_appoint_jump_click_ratio,
+       union_event_pay_purchase_amount_7d,
+       union_event_pay_purchase_amount_7d_roi,
+       placement_type,
+       ad_scene,
+       event_order_successed,
+       ad_photo_played_10s_ratio,
+       key_action_cost,
+       event_add_shopping_cart_cost,
+       event_ad_watch_times_ratio,
+       event_outbound_call_cost,
+       event_outbound_call,
+       action_new_ratio,
+       event_watch_app_ad,
+       event_multi_conversion_cost,
+       event_phone_card_activate,
+       ad_photo_played_75percent_ratio,
+       key_action_ratio,
+       event_ad_watch_times_cost,
+       event_add_shopping_cart,
+       key_action,
+       event_multi_conversion,
+       event_wechat_connected,
+       event_dsp_gift_form,
+       event_intention_confirmed,
+       event_phone_get_through,
+       event_multi_conversion_ratio,
+       event_measurement_house,
+       ad_photo_played_2s_ratio,
+       event_outbound_call_ratio,
+       event_ad_watch_times,
+       video.signature,
+       sys.channel_type ,
+       sys.clip_name,
+       sys.shot_name,
+       sys.plan_name,
+       sys.leader_name,
+       sys.video_name,
+       sys.channel_name,
+       sys.clip_company_id
+from media_api.kuaishou_material_video_report_hourly report
+    left join media_api.kuaishou_video_list video
+    on report.advertiser_id=video.advertiser_id and report.photo_id=video.photo_id
+         left join
+     hcst_system.ctop_material_attribution_info sys
+     on report.advertiser_id = sys.account_id
+ where report.stat_date between {start_time} and {end_time} and  report.photo_id!=0
+  order by advertiser_id,photo_id ,stat_date,`hour` limit {num},5000""".format(
+                    start_time=self.start_time, end_time=self.end_time, num=i * 5000)
+                TidbConn.exec_sql(self.conn, sql)
+                self.conn.commit()
+                return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = MateirialVideoHourlyReport().hourly_report()
+
+    if status == 0:
+        logging.info("作业执行成功")
+    else:
+        logging.info("作业执行失败")

+ 223 - 0
Apietl/kwai_etl/report/UnitDailyReport.py

@@ -0,0 +1,223 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 5:10 下午
+# @Site    :
+# @File    : UnitReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+
+import logging
+from math import ceil
+from Apietl.utlis.Utils import Utils
+from TidbConn import TidbConn
+
+
+class UnitDailyReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    def daily_report(self):
+        try:
+            sql = """select count(1) from media_api.kuaishou_unit_report_daily where 
+            stat_date between {start_time} and {end_time}""".format(
+                start_time=self.start_time, end_time=self.end_time)
+            totalNum = TidbConn.quary(sql)[0][0]
+            pageCount = ceil(totalNum / 5000)
+            for i in range(pageCount):
+                sql = """replace into application.kuaishou_unit_report_daily_dw
+(account_id, stat_date, campaign_id, campaign_name, unit_id, unit_name, project_id, product_id, advertiser_id,
+ company_id, account_name, project_name, advertiser_name, company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio, play_3s_ratio, action_ratio,
+ impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow, cancel_follow, report, block,
+ negative, submit, download_started, download_completed, activation, event_pay_first_day,
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
+ event_outbound_call_ratio, event_ad_watch_times)
+        select report.advertiser_id as account_id,
+               report.stat_date,
+               report.campaign_id,
+               report.campaign_name,
+               report.unit_id,
+               report.unit_name,
+               sys.project_id,
+               sys.product_id,
+               sys.advertiser_id,
+               sys.company_id,
+               sys.account_name,
+               sys.project_name,
+               sys.advertiser_name,
+               sys.company_name,
+               sys.sale_id,
+               sys.user_id,
+               sys.org_code,
+               report.charge,
+               report.`show`,
+               report.photo_click,
+               report.aclick,
+               report.bclick,
+               report.photo_click_ratio,
+               report.play_3s_ratio,
+               report.action_ratio,
+               report.impression_1k_cost,
+               report.photo_click_cost,
+               report.action_cost,
+               report.share,
+               report.comment,
+               report.`like`,
+               report.follow,
+               report.cancel_follow,
+               report.report,
+               report.block,
+               report.negative,
+               report.submit,
+               report.download_started,
+               report.download_completed,
+               report.activation,
+               report.event_pay_first_day,
+               report.event_pay_purchase_amount_first_day,
+               report.event_pay_first_day_roi,
+               report.event_pay,
+               report.event_pay_purchase_amount,
+               report.event_pay_roi,
+               report.event_register,
+               report.event_register_cost,
+               report.event_register_ratio,
+               report.event_jin_jian_app,
+               report.event_jin_jian_app_cost,
+               report.event_credit_grant_app,
+               report.event_credit_grant_app_cost,
+               report.event_credit_grant_app_ratio,
+               report.event_order_paid,
+               report.event_order_paid_purchase_amount,
+               report.event_order_paid_cost,
+               report.event_next_day_stay,
+               report.event_next_day_stay_cost,
+               report.event_next_day_stay_ratio,
+               report.form_count,
+               report.form_cost,
+               report.form_action_ratio,
+               report.event_jin_jian_landing_page,
+               report.event_jin_jian_landing_page_cost,
+               report.event_credit_grant_landing_page,
+               report.event_credit_grant_landing_page_cost,
+               report.event_credit_grant_landing_page_ratio,
+               report.event_valid_clues,
+               report.event_valid_clues_cost,
+               report.event_add_wechat,
+               report.event_add_wechat_cost,
+               report.event_add_wechat_ratio,
+               report.event_get_through,
+               report.event_get_through_cost,
+               report.event_get_through_ratio,
+               report.event_app_invoked,
+               report.event_app_invoked_cost,
+               report.event_app_invoked_ratio,
+               report.event_credit_grant_landing_ratio,
+               report.play_5s_ratio,
+               report.play_end_ratio,
+               report.event_new_user_pay,
+               report.event_new_user_pay_cost,
+               report.event_new_user_pay_ratio,
+               report.click_1k_cost,
+               report.ad_product_cnt,
+               report.event_goods_view,
+               report.merchant_reco_fans,
+               report.event_order_amount_roi,
+               report.event_goods_view_cost,
+               report.merchant_reco_fans_cost,
+               report.event_button_click,
+               report.event_button_click_cost,
+               report.event_button_click_ratio,
+               report.event_order_paid_roi,
+               report.event_new_user_jinjian_app,
+               report.event_new_user_jinjian_app_cost,
+               report.event_new_user_jinjian_app_roi,
+               report.event_new_user_credit_grant_app,
+               report.event_new_user_credit_grant_app_cost,
+               report.event_new_user_credit_grant_app_roi,
+               report.event_new_user_jinjian_page,
+               report.event_new_user_jinjian_page_cost,
+               report.event_new_user_jinjian_page_roi,
+               report.event_new_user_credit_grant_page,
+               report.event_new_user_credit_grant_page_cost,
+               report.event_new_user_credit_grant_page_roi,
+               report.event_appoint_form,
+               report.event_appoint_form_cost,
+               report.event_appoint_form_ratio,
+               report.event_appoint_jump_click,
+               report.event_appoint_jump_click_cost,
+               report.event_appoint_jump_click_ratio,
+               report.union_event_pay_purchase_amount_7d,
+               report.union_event_pay_purchase_amount_7d_roi,
+               report.placement_type,
+               report.ad_scene,
+               report.event_order_successed,
+               report.ad_photo_played_10s_ratio,
+               report.key_action_cost,
+               report.event_add_shopping_cart_cost,
+               report.event_ad_watch_times_ratio,
+               report.event_outbound_call_cost,
+               report.event_outbound_call,
+               report.action_new_ratio,
+               report.event_watch_app_ad,
+               report.event_multi_conversion_cost,
+               report.event_phone_card_activate,
+               report.ad_photo_played_75percent_ratio,
+               report.key_action_ratio,
+               report.event_ad_watch_times_cost,
+               report.event_add_shopping_cart,
+               report.key_action,
+               report.event_multi_conversion,
+               report.event_wechat_connected,
+               report.event_dsp_gift_form,
+               report.event_intention_confirmed,
+               report.event_phone_get_through,
+               report.event_multi_conversion_ratio,
+               report.event_measurement_house,
+               report.ad_photo_played_2s_ratio,
+               report.event_outbound_call_ratio,
+               report.event_ad_watch_times
+        from media_api.kuaishou_unit_report_daily report
+                 left join
+             hcst_system.ctop_account_attribution_info sys
+             on report.advertiser_id = sys.account_id
+        where report.stat_date between {start_time} and {end_time} order by unit_id,stat_date limit {num},5000""".\
+                    format(start_time=self.start_time, end_time=self.end_time, num=i * 5000)
+                TidbConn.exec_sql(self.conn, sql)
+                self.conn.commit()
+                return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = UnitDailyReport().daily_report()
+    if status == 0:
+        logging.info("作业执行成功")
+    else:
+        logging.info("作业执行失败")

+ 227 - 0
Apietl/kwai_etl/report/UnitHourlyReport.py

@@ -0,0 +1,227 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 5:10 下午
+# @Site    :
+# @File    : UnitHourlyReport.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+
+import logging
+from math import ceil
+
+import pandas as pd
+from sqlalchemy import create_engine
+from Apietl.utlis.Utils import Utils
+from TidbConn import TidbConn
+
+
+class UnitHourlyReport:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    def hourly_report(self):
+        try:
+            sql = """select count(1) from media_api.kuaishou_unit_report_hourly where 
+            stat_date between {start_time} and {end_time}""".format(
+                start_time=self.start_time, end_time=self.end_time)
+            totalNum = TidbConn.quary(sql)[0][0]
+            pageCount = ceil(totalNum / 5000)
+            for i in range(pageCount):
+                sql = """replace into application.kuaishou_unit_report_hourly_dw
+(account_id, stat_date,`hour`, campaign_id, campaign_name, unit_id, unit_name, project_id, product_id, advertiser_id,
+ company_id, account_name, project_name, advertiser_name, company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio, play_3s_ratio, action_ratio,
+ impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow, cancel_follow, report, block,
+ negative, submit, download_started, download_completed, activation, event_pay_first_day,
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
+ event_outbound_call_ratio, event_ad_watch_times)
+        select report.advertiser_id as account_id,
+               report.stat_date,
+               report.hour,
+               report.campaign_id,
+               report.campaign_name,
+               report.unit_id,
+               report.unit_name,
+               sys.project_id,
+               sys.product_id,
+               sys.advertiser_id,
+               sys.company_id,
+               sys.account_name,
+               sys.project_name,
+               sys.advertiser_name,
+               sys.company_name,
+               sys.sale_id,
+               sys.user_id,
+               sys.org_code,
+               report.charge,
+               report.`show`,
+               report.photo_click,
+               report.aclick,
+               report.bclick,
+               report.photo_click_ratio,
+               report.play_3s_ratio,
+               report.action_ratio,
+               report.impression_1k_cost,
+               report.photo_click_cost,
+               report.action_cost,
+               report.share,
+               report.comment,
+               report.`like`,
+               report.follow,
+               report.cancel_follow,
+               report.report,
+               report.block,
+               report.negative,
+               report.submit,
+               report.download_started,
+               report.download_completed,
+               report.activation,
+               report.event_pay_first_day,
+               report.event_pay_purchase_amount_first_day,
+               report.event_pay_first_day_roi,
+               report.event_pay,
+               report.event_pay_purchase_amount,
+               report.event_pay_roi,
+               report.event_register,
+               report.event_register_cost,
+               report.event_register_ratio,
+               report.event_jin_jian_app,
+               report.event_jin_jian_app_cost,
+               report.event_credit_grant_app,
+               report.event_credit_grant_app_cost,
+               report.event_credit_grant_app_ratio,
+               report.event_order_paid,
+               report.event_order_paid_purchase_amount,
+               report.event_order_paid_cost,
+               report.event_next_day_stay,
+               report.event_next_day_stay_cost,
+               report.event_next_day_stay_ratio,
+               report.form_count,
+               report.form_cost,
+               report.form_action_ratio,
+               report.event_jin_jian_landing_page,
+               report.event_jin_jian_landing_page_cost,
+               report.event_credit_grant_landing_page,
+               report.event_credit_grant_landing_page_cost,
+               report.event_credit_grant_landing_page_ratio,
+               report.event_valid_clues,
+               report.event_valid_clues_cost,
+               report.event_add_wechat,
+               report.event_add_wechat_cost,
+               report.event_add_wechat_ratio,
+               report.event_get_through,
+               report.event_get_through_cost,
+               report.event_get_through_ratio,
+               report.event_app_invoked,
+               report.event_app_invoked_cost,
+               report.event_app_invoked_ratio,
+               report.event_credit_grant_landing_ratio,
+               report.play_5s_ratio,
+               report.play_end_ratio,
+               report.event_new_user_pay,
+               report.event_new_user_pay_cost,
+               report.event_new_user_pay_ratio,
+               report.click_1k_cost,
+               report.ad_product_cnt,
+               report.event_goods_view,
+               report.merchant_reco_fans,
+               report.event_order_amount_roi,
+               report.event_goods_view_cost,
+               report.merchant_reco_fans_cost,
+               report.event_button_click,
+               report.event_button_click_cost,
+               report.event_button_click_ratio,
+               report.event_order_paid_roi,
+               report.event_new_user_jinjian_app,
+               report.event_new_user_jinjian_app_cost,
+               report.event_new_user_jinjian_app_roi,
+               report.event_new_user_credit_grant_app,
+               report.event_new_user_credit_grant_app_cost,
+               report.event_new_user_credit_grant_app_roi,
+               report.event_new_user_jinjian_page,
+               report.event_new_user_jinjian_page_cost,
+               report.event_new_user_jinjian_page_roi,
+               report.event_new_user_credit_grant_page,
+               report.event_new_user_credit_grant_page_cost,
+               report.event_new_user_credit_grant_page_roi,
+               report.event_appoint_form,
+               report.event_appoint_form_cost,
+               report.event_appoint_form_ratio,
+               report.event_appoint_jump_click,
+               report.event_appoint_jump_click_cost,
+               report.event_appoint_jump_click_ratio,
+               report.union_event_pay_purchase_amount_7d,
+               report.union_event_pay_purchase_amount_7d_roi,
+               report.placement_type,
+               report.ad_scene,
+               report.event_order_successed,
+               report.ad_photo_played_10s_ratio,
+               report.key_action_cost,
+               report.event_add_shopping_cart_cost,
+               report.event_ad_watch_times_ratio,
+               report.event_outbound_call_cost,
+               report.event_outbound_call,
+               report.action_new_ratio,
+               report.event_watch_app_ad,
+               report.event_multi_conversion_cost,
+               report.event_phone_card_activate,
+               report.ad_photo_played_75percent_ratio,
+               report.key_action_ratio,
+               report.event_ad_watch_times_cost,
+               report.event_add_shopping_cart,
+               report.key_action,
+               report.event_multi_conversion,
+               report.event_wechat_connected,
+               report.event_dsp_gift_form,
+               report.event_intention_confirmed,
+               report.event_phone_get_through,
+               report.event_multi_conversion_ratio,
+               report.event_measurement_house,
+               report.ad_photo_played_2s_ratio,
+               report.event_outbound_call_ratio,
+               report.event_ad_watch_times
+        from media_api.kuaishou_unit_report_hourly report
+                 left join
+             hcst_system.ctop_account_attribution_info sys
+             on report.advertiser_id = sys.account_id
+        where report.stat_date between {start_time} and {end_time} order by unit_id,hour,stat_date limit {num},5000""".\
+                    format(start_time=self.start_time, end_time=self.end_time,num=i * 5000)
+                TidbConn.exec_sql(self.conn, sql)
+                self.conn.commit()
+                return 0
+        except Exception as e:
+            logging.error(e)
+            return -1
+
+
+if __name__ == '__main__':
+    status = UnitHourlyReport().hourly_report()
+    if status == 0:
+        logging.info("作业执行成功")
+    else:
+        logging.info("作业执行失败")

+ 102 - 0
Apietl/utlis/LoggerConfig.py

@@ -0,0 +1,102 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 11:14 上午
+# @Site    :
+# @File    : ConfConstant.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+"""
+logging配置
+"""
+
+import logging.config
+import os
+import time
+
+from Apietl.constant.ConfConstant import ConfConstant
+
+
+class Loggers:
+
+    def __init__(self, log_name):
+        """初始化日志"""
+        self.__ini_log(log_name=log_name)
+
+    @staticmethod
+    def __get_local_time():
+        # 获取当前时间
+        time_now = int(time.time())
+        # 转换成localtime
+        time_local = time.localtime(time_now)
+        # 转换成新的时间格式(2016-05-09 18:59:20)
+        dt = time.strftime("%Y%m%d", time_local)
+
+        return dt
+
+    def __ini_log(self, log_name):
+        # 定义三种日志输出格式 开始
+
+        standard_format = '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \
+                          '[%(levelname)s][%(message)s]'  # 其中name为getlogger指定的名字
+
+        simple_format = '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
+
+        # id_simple_format = '[%(levelname)s][%(asctime)s] %(message)s'
+
+        # 定义日志输出格式 结束
+
+        # logfile_dir = os.path.dirname(os.path.abspath(__file__))  # log文件的目录
+        logfile_dir = os.path.dirname(ConfConstant.LOG_DIR)  # log文件的目录
+
+        logfile_name = '{}_{}.log'.format(log_name, self.__get_local_time())  # log文件名
+
+        # 如果不存在定义的日志目录就创建一个
+        if not os.path.isdir(logfile_dir):
+            os.mkdir(logfile_dir)
+
+        # log文件的全路径
+        logfile_path = os.path.join(logfile_dir, logfile_name)
+
+        # log配置字典
+        logging_dic = {
+            'version': 1,
+            'disable_existing_loggers': False,
+            'formatters': {
+                'standard': {
+                    'format': standard_format
+                },
+                'simple': {
+                    'format': simple_format
+                },
+            },
+            'filters': {},
+            'handlers': {
+                # 打印到终端的日志
+                'console': {
+                    'level': 'DEBUG',
+                    'class': 'logging.StreamHandler',  # 打印到屏幕
+                    'formatter': 'simple'
+                },
+                # 打印到文件的日志,收集info及以上的日志
+                'default': {
+                    'level': 'DEBUG',
+                    'class': 'logging.handlers.RotatingFileHandler',  # 保存到文件
+                    'formatter': 'standard',
+                    'filename': logfile_path,  # 日志文件
+                    # 'maxBytes': 1024*1024*5,  # 日志大小 5M
+                    'backupCount': 5,
+                    'encoding': 'utf-8',  # 日志文件的编码,再也不用担心中文log乱码了
+                },
+            },
+            'loggers': {
+                '': {
+                    'handlers': ['default', 'console'],  # 这里把上面定义的两个handler都加上,即log数据既写入文件又打印到屏幕
+                    'level': ConfConstant.LOG_LEVEL,
+                    'propagate': True,  # 向上(更高level的logger)传递
+                },
+            },
+        }
+
+        logging.config.dictConfig(logging_dic)  # 导入上面定义的logging配置
+        logging.getLogger(__name__)  # 生成一个log实例

+ 28 - 0
Apietl/utlis/Utils.py

@@ -0,0 +1,28 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/9/15 11:06 上午
+# @Site    :
+# @File    : Utils.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+import argparse
+import ast
+import getopt
+import sys
+from urllib.parse import unquote
+
+
+class Utils:
+    """
+    参数获取工具类
+    """
+
+    @staticmethod
+    def get_args():
+        parser = argparse.ArgumentParser(description='')
+        parser.add_argument('-start_time', type=str, default=None, help="TX_DT")
+        parser.add_argument('-end_time', type=str, default=None, help="TX_DT")
+        args = parser.parse_args()
+        start_time = args.start_time
+        end_time = args.end_time
+        return start_time, end_time

+ 33 - 0
Apietl/utlis/webHook.py

@@ -0,0 +1,33 @@
+import datetime
+import logging
+import traceback
+
+import requests
+from flask import json  # To read json data
+from flask import request  # To receive headers
+from flask import Flask  # To be able to start the application
+from rocketmq.client import Producer, Message
+
+from ConfConstant import ConfConstant
+from report.AccountReport import AccountReport
+
+app = Flask(__name__)
+
+
+@app.route('/')
+def api_root():
+    return 'Welcome guys'
+
+
+@app.route('/webhook/account', methods=['POST'])
+def api_webhook_messages():
+    my_info = json.loads(request.param)
+    account_id = my_info["account_id"]
+    start_date = my_info["start_time"]
+    end_date = my_info["end_time"]
+    date_type = my_info["date_type"]
+    AccountReport().handler(date_type, account_id, start_date, end_date)
+
+
+if __name__ == '__main__':
+    app.run(port=8765, host=ConfConstant.URL, debug=True)