|
@@ -0,0 +1,108 @@
|
|
|
+import pandas as pd
|
|
|
+import numpy as np
|
|
|
+import datetime
|
|
|
+import pymysql
|
|
|
+from sqlalchemy import create_engine
|
|
|
+
|
|
|
+# online_con_str = "mysql+pymysql://%s:%s@%s:%d/%s" % ("readonly", "hcst@2021", "139.186.27.96", 4000, "jeecg-boot")
|
|
|
+# engine = create_engine(online_con_str, connect_args={'charset': 'utf8'})
|
|
|
+
|
|
|
+# test_con_str = "mysql+pymysql://%s:%s@%s:%d/%s" % ("hcst", "hcst2020", "139.186.151.174", 3306, "jeecg-boot")
|
|
|
+# engine = create_engine(test_con_str, connect_args={'charset': 'utf8'})
|
|
|
+
|
|
|
+online_con_str = "mysql+pymysql://%s:%s@%s:%d/%s" % ("hcst", "hcst@2020", "139.186.151.174", 3306, "jeecg-boot")
|
|
|
+engine = create_engine(online_con_str, connect_args={'charset': 'utf8'})
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 拼接请求的json
|
|
|
+# example: 整个项目近30天内,消耗top10的视频,创建组
|
|
|
+account_id = 9556344
|
|
|
+request_dict = {}
|
|
|
+# 1、读取 客户策略表中 status = 1 的记录 (ctop_ai_kuaishou_advertiser_strategy)
|
|
|
+get_advertiser_strategy_sql = """
|
|
|
+select *
|
|
|
+from ctop_ai_kuaishou_advertiser_strategy
|
|
|
+where account_id = %d
|
|
|
+and status = 1
|
|
|
+""" % account_id
|
|
|
+advertiser_strategy_df = pd.read_sql(get_advertiser_strategy_sql, engine)
|
|
|
+advertiser_strategy_drop_cols = ['id', 'status', 'create_time', 'effective_time', 'expiry_time']
|
|
|
+advertiser_strategy_df.drop(columns=advertiser_strategy_drop_cols, inplace=True)
|
|
|
+request_dict['advertiser_strategy_info'] = advertiser_strategy_df.T.to_dict()[0]
|
|
|
+
|
|
|
+# 2、拼接请求的json
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 2.1 获取需要创建广告组所需要的视频
|
|
|
+# 调用于蒙的视频接口
|
|
|
+
|
|
|
+# 获取视频方式一
|
|
|
+days = 30
|
|
|
+num = 10
|
|
|
+sql = """
|
|
|
+select * from ctop_kuaishou_video_get
|
|
|
+ where account_id = %d
|
|
|
+ and signature in
|
|
|
+ (
|
|
|
+ select
|
|
|
+ daily_material.signature
|
|
|
+ from
|
|
|
+ ctop_kuaishou_report_daily_material daily_material
|
|
|
+ inner join
|
|
|
+ ctop_user_allocation allocation
|
|
|
+ on daily_material.account_id = allocation.account_id
|
|
|
+ where allocation.project_id in (select project_id from ctop_user_allocation where account_id = %d)
|
|
|
+ and to_days(now()) - to_days(daily_material.stat_date) <= %d
|
|
|
+ and daily_material.signature is not null
|
|
|
+ GROUP BY daily_material.signature
|
|
|
+ order by sum(daily_material.charge) desc
|
|
|
+ limit %d
|
|
|
+ )
|
|
|
+""" % (account_id, account_id, days, num)
|
|
|
+# video_df = pd.read_sql(sql, engine)
|
|
|
+# print(video_df.shape)
|
|
|
+
|
|
|
+# 获取视频方式二
|
|
|
+# 离线分析手动提取 signature,然后创建广告组
|
|
|
+# signature_list = ['f17059ef15d5940a43bd38f9b13dc551', 'c0065cbd882d94c7c0a808db68f73666']
|
|
|
+# sql = """
|
|
|
+# select * from ctop_kuaishou_video_get
|
|
|
+# where account_id = %d
|
|
|
+# and signature in %s
|
|
|
+# """ % (account_id, tuple(signature_list))
|
|
|
+# video_df = pd.read_sql(sql, engine)
|
|
|
+# print(video_df)
|
|
|
+
|
|
|
+# 2.1 计划层级的参数
|
|
|
+campaign_name = "户14-上下滑&信息流-跑量视频-剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-" + \
|
|
|
+ datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
|
|
|
+# campaign_id 为空表示需要创建广告计划, 不为空则表示在该广告计划下新增广告组
|
|
|
+campaign_dict = {}
|
|
|
+campaign_id = None
|
|
|
+campaign_dict['campaign_name'] = campaign_name
|
|
|
+campaign_dict['campaign_id'] = campaign_id
|
|
|
+campaign_dict['campaign_type'] = 2
|
|
|
+campaign_dict['day_budget'] = None
|
|
|
+campaign_dict['day_budget_schedule'] = None
|
|
|
+campaign_dict['operation_type'] = "add"
|
|
|
+
|
|
|
+request_dict['campaign'] = campaign_dict
|
|
|
+
|
|
|
+
|
|
|
+# 2.2 组层级的参数
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|