|
@@ -10,7 +10,7 @@ from utils.ConstantConfig import *
|
|
from utils.DataBaseConfig import *
|
|
from utils.DataBaseConfig import *
|
|
from utils.CommonFunction import get_history_video_info, get_new_video_info, get_missing_video_info, \
|
|
from utils.CommonFunction import get_history_video_info, get_new_video_info, get_missing_video_info, \
|
|
get_top_video_info, get_campaign_and_group_name_rule, get_app_detail, get_request_data,\
|
|
get_top_video_info, get_campaign_and_group_name_rule, get_app_detail, get_request_data,\
|
|
- refresh_video
|
|
|
|
|
|
+ refresh_video, get_app_list
|
|
|
|
|
|
from ai_strategy_request_func import ai_strategy_request_parse
|
|
from ai_strategy_request_func import ai_strategy_request_parse
|
|
|
|
|
|
@@ -45,69 +45,83 @@ class AiHistoricalMissingMaterial(tornado.web.RequestHandler):
|
|
df = pd.read_sql(sql, engine)
|
|
df = pd.read_sql(sql, engine)
|
|
if df['general_track'].values[0] == 0:
|
|
if df['general_track'].values[0] == 0:
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
- random.shuffle(app_id_array)
|
|
|
|
- app_id_cnt = 0
|
|
|
|
- for app_id in app_id_array:
|
|
|
|
- campaign_id = None
|
|
|
|
- # 1、获取该 app_id 的应该详情
|
|
|
|
- app_id_info = get_app_detail(account_id=account_id,
|
|
|
|
- url=get_app_detail_url,
|
|
|
|
- app_id=app_id)
|
|
|
|
- if app_id_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 2、依据 appVersion 的值,来判断是否已经有对应的计划,如果有则获取 campaign_id,没有则设置 campaign_name
|
|
|
|
- app_version = app_id_info['data'].get('appVersion', 'error')
|
|
|
|
- track_url = app_id_info['data'].get('trackUrl', 'error')
|
|
|
|
-
|
|
|
|
- sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
- where account_id = %s
|
|
|
|
- """ % account_id
|
|
|
|
- campaign_df = pd.read_sql(sql, engine)
|
|
|
|
- for row in campaign_df.itertuples():
|
|
|
|
- if (app_version + '--优选广告位-' + '遗漏素材') == getattr(row, 'campaign_name'):
|
|
|
|
- campaign_id = getattr(row, 'campaign_id')
|
|
|
|
- break
|
|
|
|
-
|
|
|
|
- # 3、获取通用视频1个
|
|
|
|
- general_video_info = get_missing_video_info(account_id=account_id,
|
|
|
|
- cnt=1,
|
|
|
|
- url=get_missing_video_url,
|
|
|
|
- start_time=missing_video_start_time,
|
|
|
|
- end_time=missing_video_end_time,
|
|
|
|
- app_version='all')
|
|
|
|
- # 4、获取app_id对应的视频1个
|
|
|
|
- special_video_info = get_missing_video_info(account_id=account_id,
|
|
|
|
- cnt=1,
|
|
|
|
- url=get_missing_video_url,
|
|
|
|
- start_time=missing_video_start_time,
|
|
|
|
- end_time=missing_video_end_time,
|
|
|
|
- app_version=app_version)
|
|
|
|
- # 5、video_info 合并
|
|
|
|
- full_video_info = []
|
|
|
|
- if general_video_info['code'] == 0:
|
|
|
|
- full_video_info.extend(general_video_info['data'])
|
|
|
|
- if special_video_info['code'] == 0:
|
|
|
|
- full_video_info.extend(special_video_info['data'])
|
|
|
|
-
|
|
|
|
- # 6、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
- # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
- # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
|
|
- if full_video_info:
|
|
|
|
- request_data = get_request_data(account_id=account_id,
|
|
|
|
- campaign_id=campaign_id,
|
|
|
|
- video_info=full_video_info,
|
|
|
|
- campaign_name=app_version + '--优选广告位-' + '遗漏素材',
|
|
|
|
- group_name=app_version + '-优选广告位-不限-自定义-' + '遗漏素材',
|
|
|
|
- ai_strategy_remark="补充遗漏素材",
|
|
|
|
- unit_type=4,
|
|
|
|
- app_id=app_id,
|
|
|
|
- click_track_url=track_url)
|
|
|
|
- request = ai_strategy_request_parse(request_data)
|
|
|
|
- logger.info("account_id=%s, app_id=%s, 补充遗漏素材,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
- app_id_cnt += 1
|
|
|
|
- if app_id_cnt >= missing_video_app_id:
|
|
|
|
- break
|
|
|
|
|
|
+ app_list = get_app_list(account_id=account_id, url=get_app_list_url)
|
|
|
|
+ # app_dict key = ("appVersion": "ksjyrlyn-人类一脑涂地大败") , value = 完整的app_id信息
|
|
|
|
+ app_dict = {}
|
|
|
|
+ for app_info in app_list['data']:
|
|
|
|
+ if app_info['appId'] in app_id_array:
|
|
|
|
+ app_dict[app_info['appVersion']] = app_info
|
|
|
|
+ video_list = get_missing_video_info(account_id=account_id,
|
|
|
|
+ cnt=missing_video_cnt,
|
|
|
|
+ url=get_missing_video_url,
|
|
|
|
+ start_time=missing_video_start_time,
|
|
|
|
+ end_time=missing_video_end_time)
|
|
|
|
+ # 返回视频中有通用视频和特定视频,需要分开处理
|
|
|
|
+ # "photo_name": "all",
|
|
|
|
+ # "photo_name": "ksjytdrca-糖豆人冲啊",
|
|
|
|
+ if video_list['code'] == 0:
|
|
|
|
+ video_df = pd.DataFrame(video_list['data'])
|
|
|
|
+ # 1-非通用视频的创建
|
|
|
|
+ special_video_df = video_df[video_df.photo_name != 'all']
|
|
|
|
+ for photo_name in special_video_df['photo_name'].unique():
|
|
|
|
+ if photo_name in app_dict.keys():
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[photo_name].get('appId', 'error')
|
|
|
|
+ app_version = app_dict[photo_name].get('appVersion', 'error')
|
|
|
|
+ track_url = app_dict[photo_name].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '遗漏素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ app_id_video_df = special_video_df[special_video_df.photo_name == photo_name]
|
|
|
|
+ app_id_video_list = []
|
|
|
|
+ for k, v in app_id_video_df.T.to_dict().items():
|
|
|
|
+ app_id_video_list.append(v)
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=app_id_video_list,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '遗漏素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '遗漏素材',
|
|
|
|
+ ai_strategy_remark="补充遗漏素材",
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 补充遗漏素材-特定视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+ # 2-通用视频的创建,random.shuffle 选择 app_id
|
|
|
|
+ general_video_df = video_df[video_df.photo_name == 'all']
|
|
|
|
+ if not general_video_df.empty:
|
|
|
|
+ general_video_cnt = len(general_video_df)
|
|
|
|
+ app_version_list = list(app_dict)
|
|
|
|
+ random.shuffle(app_version_list)
|
|
|
|
+ video_cnt = 0
|
|
|
|
+ for app_version in app_version_list[:general_video_cnt]:
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[app_version].get('appId', 'error')
|
|
|
|
+ track_url = app_dict[app_version].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '遗漏素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ single_video = [general_video_df.iloc[video_cnt, :].T.to_dict()]
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=single_video,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '遗漏素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '遗漏素材',
|
|
|
|
+ ai_strategy_remark="补充遗漏素材",
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ video_cnt += 1
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 补充遗漏素材-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+ else:
|
|
|
|
+ logger.info("account_id=%s, 补充遗漏素材: 返回的视频中没有通用视频" % account_id)
|
|
self.write(json.dumps({"message": "account_id=%s, 多应用的补充遗漏素材请求已走完!" % account_id}))
|
|
self.write(json.dumps({"message": "account_id=%s, 多应用的补充遗漏素材请求已走完!" % account_id}))
|
|
self.flush()
|
|
self.flush()
|
|
else:
|
|
else:
|
|
@@ -147,7 +161,7 @@ class AiHistoricalMissingMaterial(tornado.web.RequestHandler):
|
|
|
|
|
|
class AiAutoCreative(tornado.web.RequestHandler):
|
|
class AiAutoCreative(tornado.web.RequestHandler):
|
|
"""
|
|
"""
|
|
- 每5分钟,检查一次是否有上新素材,有的话,就自动创建 -- 需要上定时任务测试
|
|
|
|
|
|
+ 每5分钟,检查一次是否有上新素材,有的话,就自动创建
|
|
"""
|
|
"""
|
|
def post(self):
|
|
def post(self):
|
|
data = self.request.body
|
|
data = self.request.body
|
|
@@ -170,62 +184,85 @@ class AiAutoCreative(tornado.web.RequestHandler):
|
|
df = pd.read_sql(sql, engine)
|
|
df = pd.read_sql(sql, engine)
|
|
if df['general_track'].values[0] == 0:
|
|
if df['general_track'].values[0] == 0:
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
- random.shuffle(app_id_array)
|
|
|
|
- for app_id in app_id_array:
|
|
|
|
- campaign_id = None
|
|
|
|
- # 1、获取该 app_id 的应该详情
|
|
|
|
- app_id_info = get_app_detail(account_id=account_id,
|
|
|
|
- url=get_app_detail_url,
|
|
|
|
- app_id=app_id)
|
|
|
|
- if app_id_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 2、依据 appVersion 的值,来判断是否已经有对应的计划,如果有则获取 campaign_id,没有则设置 campaign_name
|
|
|
|
- app_version = app_id_info['data'].get('appVersion', 'error')
|
|
|
|
- track_url = app_id_info['data'].get('trackUrl', 'error')
|
|
|
|
-
|
|
|
|
- sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
- where account_id = %s """ % account_id
|
|
|
|
- campaign_df = pd.read_sql(sql, engine)
|
|
|
|
- for row in campaign_df.itertuples():
|
|
|
|
- if (app_version + '--优选广告位-' + '素材自动上新') == getattr(row, 'campaign_name'):
|
|
|
|
- campaign_id = getattr(row, 'campaign_id')
|
|
|
|
- break
|
|
|
|
|
|
+ app_list = get_app_list(account_id=account_id, url=get_app_list_url)
|
|
|
|
+ # app_dict key = ("appVersion": "ksjyrlyn-人类一脑涂地大败") , value = 完整的app_id信息
|
|
|
|
+ app_dict = {}
|
|
|
|
+ for app_info in app_list['data']:
|
|
|
|
+ if app_info['appId'] in app_id_array:
|
|
|
|
+ app_dict[app_info['appVersion']] = app_info
|
|
|
|
+ video_list = get_new_video_info(account_id=account_id,
|
|
|
|
+ url=get_new_video_url)
|
|
|
|
|
|
- # 3、获取通用视频
|
|
|
|
- general_video_info = get_new_video_info(account_id=account_id,
|
|
|
|
- url=get_new_video_url,
|
|
|
|
- app_version='all')
|
|
|
|
- # 4、获取app_id对应的特定视频
|
|
|
|
- special_video_info = get_new_video_info(account_id=account_id,
|
|
|
|
- url=get_new_video_url,
|
|
|
|
- app_version=app_version)
|
|
|
|
- # 5、video_info 合并
|
|
|
|
- full_video_info = []
|
|
|
|
- if general_video_info['code'] == 0:
|
|
|
|
- full_video_info.extend(general_video_info['data'])
|
|
|
|
- if special_video_info['code'] == 0:
|
|
|
|
- full_video_info.extend(special_video_info['data'])
|
|
|
|
-
|
|
|
|
- # 6、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
- # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
- # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
|
|
- if full_video_info:
|
|
|
|
- request_data = get_request_data(account_id=account_id,
|
|
|
|
- campaign_id=campaign_id,
|
|
|
|
- video_info=full_video_info,
|
|
|
|
- campaign_name=app_version + '--优选广告位-' + '素材自动上新',
|
|
|
|
- group_name=app_version + '-优选广告位-不限-自定义-' + '素材自动上新',
|
|
|
|
- ai_strategy_remark="素材自动上新",
|
|
|
|
- unit_type=4,
|
|
|
|
- app_id=app_id,
|
|
|
|
- click_track_url=track_url)
|
|
|
|
- request = ai_strategy_request_parse(request_data)
|
|
|
|
- logger.info("account_id=%s, app_id=%s, 素材自动上新,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
|
|
+ # 返回的视频中有通用视频和特定视频,需要分开处理
|
|
|
|
+ # "photo_name": "all",
|
|
|
|
+ # "photo_name": "ksjytdrca-糖豆人冲啊",
|
|
|
|
+ if video_list['code'] == 0:
|
|
|
|
+ video_df = pd.DataFrame(video_list['data'])
|
|
|
|
+ # 1-特定视频的创建
|
|
|
|
+ special_video_df = video_df[video_df.photo_name != 'all']
|
|
|
|
+ for photo_name in special_video_df['photo_name'].unique():
|
|
|
|
+ if photo_name in app_dict.keys():
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[photo_name].get('appId', 'error')
|
|
|
|
+ app_version = app_dict[photo_name].get('appVersion', 'error')
|
|
|
|
+ track_url = app_dict[photo_name].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '素材自动上新') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ app_id_video_df = special_video_df[special_video_df.photo_name == photo_name]
|
|
|
|
+ app_id_video_list = []
|
|
|
|
+ for k, v in app_id_video_df.T.to_dict().items():
|
|
|
|
+ app_id_video_list.append(v)
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=app_id_video_list,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '素材自动上新',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '素材自动上新',
|
|
|
|
+ ai_strategy_remark="素材自动上新",
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 素材自动上新-特定视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+
|
|
|
|
+ # 2-通用视频的创建,random.shuffle 选择 app_id
|
|
|
|
+ general_video_df = video_df[video_df.photo_name == 'all']
|
|
|
|
+ if not general_video_df.empty:
|
|
|
|
+ general_video_cnt = len(general_video_df)
|
|
|
|
+ app_version_list = list(app_dict)
|
|
|
|
+ random.shuffle(app_version_list)
|
|
|
|
+ video_cnt = 0
|
|
|
|
+ for app_version in app_version_list[:general_video_cnt]:
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[app_version].get('appId', 'error')
|
|
|
|
+ track_url = app_dict[app_version].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '素材自动上新') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ single_video = [general_video_df.iloc[video_cnt, :].T.to_dict()]
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=single_video,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '素材自动上新',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '素材自动上新',
|
|
|
|
+ ai_strategy_remark="素材自动上新",
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ video_cnt += 1
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 素材自动上新-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
else:
|
|
else:
|
|
- logger.info("account_id=%s, app_id=%s, 素材自动上新, 没有获取到视频,不发送ai策略请求!" % (account_id, app_id))
|
|
|
|
-
|
|
|
|
- self.write(json.dumps({"message": "account_id=%s, 多应用的素材自动上新请求已走完!" % account_id}))
|
|
|
|
|
|
+ logger.info("account_id=%s, 素材自动上新: 返回的视频中没有通用视频" % account_id)
|
|
|
|
+ else:
|
|
|
|
+ logger.info("account_id=%s, 素材自动上新: 没有获取到视频" % account_id)
|
|
|
|
+ self.write(json.dumps({"message": "account_id=%s, 多应用的素材自动上新已走完!" % account_id}))
|
|
self.flush()
|
|
self.flush()
|
|
else:
|
|
else:
|
|
start_time = (datetime.date.today()).strftime('%Y-%m-%d %H:%M:%S')
|
|
start_time = (datetime.date.today()).strftime('%Y-%m-%d %H:%M:%S')
|
|
@@ -295,73 +332,89 @@ class AiHighQualityMaterial(tornado.web.RequestHandler):
|
|
df = pd.read_sql(sql, engine)
|
|
df = pd.read_sql(sql, engine)
|
|
if df['general_track'].values[0] == 0:
|
|
if df['general_track'].values[0] == 0:
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
- random.shuffle(app_id_array)
|
|
|
|
- app_id_cnt = 0
|
|
|
|
- for app_id in app_id_array:
|
|
|
|
- campaign_id = None
|
|
|
|
- # 1、获取该 app_id 的应该详情
|
|
|
|
- app_id_info = get_app_detail(account_id=account_id,
|
|
|
|
- url=get_app_detail_url,
|
|
|
|
- app_id=app_id)
|
|
|
|
- if app_id_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 2、依据 appVersion 的值,来判断是否已经有对应的计划,如果有则获取 campaign_id,没有则设置 campaign_name
|
|
|
|
- app_version = app_id_info['data'].get('appVersion', 'error')
|
|
|
|
- track_url = app_id_info['data'].get('trackUrl', 'error')
|
|
|
|
-
|
|
|
|
- sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
- where account_id = %s """ % account_id
|
|
|
|
- campaign_df = pd.read_sql(sql, engine)
|
|
|
|
- for row in campaign_df.itertuples():
|
|
|
|
- if (app_version + '--优选广告位-' + '高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
- campaign_id = getattr(row, 'campaign_id')
|
|
|
|
- break
|
|
|
|
|
|
+ app_list = get_app_list(account_id=account_id, url=get_app_list_url)
|
|
|
|
+ # app_dict key = ("appVersion": "ksjyrlyn-人类一脑涂地大败") , value = 完整的app_id信息
|
|
|
|
+ app_dict = {}
|
|
|
|
+ for app_info in app_list['data']:
|
|
|
|
+ if app_info['appId'] in app_id_array:
|
|
|
|
+ app_dict[app_info['appVersion']] = app_info
|
|
|
|
+ video_list = get_top_video_info(account_id=account_id,
|
|
|
|
+ cnt=high_quality_video_cnt,
|
|
|
|
+ start_time=(datetime.datetime.now() +
|
|
|
|
+ datetime.timedelta(days=-high_quality_video_days)).
|
|
|
|
+ strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ url=get_high_quality_video_url)
|
|
|
|
|
|
- # 3、获取1个通用视频
|
|
|
|
- general_video_info = get_top_video_info(account_id=account_id,
|
|
|
|
- url=get_high_quality_video_url,
|
|
|
|
- start_time=(datetime.datetime.now() +
|
|
|
|
- datetime.timedelta(days=-high_quality_video_days)).
|
|
|
|
- strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- cnt=1,
|
|
|
|
- app_version='all')
|
|
|
|
- # 4、获取app_id对应的1个视频
|
|
|
|
- special_video_info = get_top_video_info(account_id=account_id,
|
|
|
|
- url=get_high_quality_video_url,
|
|
|
|
- start_time=(datetime.datetime.now() +
|
|
|
|
- datetime.timedelta(days=-high_quality_video_days)).
|
|
|
|
- strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- cnt=1,
|
|
|
|
- app_version=app_version)
|
|
|
|
-
|
|
|
|
- # 5、video_info 合并
|
|
|
|
- full_video_info = []
|
|
|
|
- if general_video_info['code'] == 0:
|
|
|
|
- full_video_info.extend(general_video_info['data'])
|
|
|
|
- if special_video_info['code'] == 0:
|
|
|
|
- full_video_info.extend(special_video_info['data'])
|
|
|
|
-
|
|
|
|
- # 6、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
- # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
- # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
|
|
- if full_video_info:
|
|
|
|
- request_data = get_request_data(account_id=account_id,
|
|
|
|
- campaign_id=campaign_id,
|
|
|
|
- video_info=full_video_info,
|
|
|
|
- campaign_name=app_version + '--优选广告位-' + '高质量素材',
|
|
|
|
- group_name=app_version + '-优选广告位-不限-自定义-' + '高质量素材',
|
|
|
|
- ai_strategy_remark="高质量素材复建",
|
|
|
|
- unit_type=4,
|
|
|
|
- app_id=app_id,
|
|
|
|
- click_track_url=track_url)
|
|
|
|
- request = ai_strategy_request_parse(request_data)
|
|
|
|
- logger.info("account_id=%s, app_id=%s, 高质量素材复建,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
- app_id_cnt += 1
|
|
|
|
- if app_id_cnt >= high_quality_video_app_id:
|
|
|
|
- break
|
|
|
|
|
|
+ # 单独处理返回的时候中,有通用视频,需要单独处理
|
|
|
|
+ # "photo_name": "all",
|
|
|
|
+ # "photo_name": "ksjytdrca-糖豆人冲啊",
|
|
|
|
+ if video_list['code'] == 0:
|
|
|
|
+ video_df = pd.DataFrame(video_list['data'])
|
|
|
|
+ # 1-特定视频的创建
|
|
|
|
+ special_video_df = video_df[video_df.photo_name != 'all']
|
|
|
|
+ for photo_name in special_video_df['photo_name'].unique():
|
|
|
|
+ if photo_name in app_dict.keys():
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[photo_name].get('appId', 'error')
|
|
|
|
+ app_version = app_dict[photo_name].get('appVersion', 'error')
|
|
|
|
+ track_url = app_dict[photo_name].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ app_id_video_df = special_video_df[special_video_df.photo_name == photo_name]
|
|
|
|
+ app_id_video_list = []
|
|
|
|
+ for k, v in app_id_video_df.T.to_dict().items():
|
|
|
|
+ app_id_video_list.append(v)
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=app_id_video_list,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '高质量素材',
|
|
|
|
+ ai_strategy_remark="高质量素材复建",
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 高质量素材复建-特定视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+
|
|
|
|
+ # 2-通用视频的创建,random.shuffle 选择 app_id
|
|
|
|
+ general_video_df = video_df[video_df.photo_name == 'all']
|
|
|
|
+ if not general_video_df.empty:
|
|
|
|
+ general_video_cnt = len(general_video_df)
|
|
|
|
+ app_version_list = list(app_dict)
|
|
|
|
+ random.shuffle(app_version_list)
|
|
|
|
+ video_cnt = 0
|
|
|
|
+ for app_version in app_version_list[:general_video_cnt]:
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[app_version].get('appId', 'error')
|
|
|
|
+ track_url = app_dict[app_version].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ single_video = [general_video_df.iloc[video_cnt, :].T.to_dict()]
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=single_video,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '高质量素材',
|
|
|
|
+ ai_strategy_remark="高质量素材复建",
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ video_cnt += 1
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 高质量素材复建-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+ else:
|
|
|
|
+ logger.info("account_id=%s, 高质量素材复建: 返回的视频中没有通用视频" % account_id)
|
|
|
|
+ else:
|
|
|
|
+ logger.info("account_id=%s, 高质量素材复建: 没有获取到视频" % account_id)
|
|
self.write(json.dumps({"message": "account_id=%s, 多应用的高质量素材复建请求已走完!" % account_id}))
|
|
self.write(json.dumps({"message": "account_id=%s, 多应用的高质量素材复建请求已走完!" % account_id}))
|
|
self.flush()
|
|
self.flush()
|
|
else:
|
|
else:
|
|
@@ -462,60 +515,92 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
|
|
""" % account_id
|
|
""" % account_id
|
|
df = pd.read_sql(sql, engine)
|
|
df = pd.read_sql(sql, engine)
|
|
if df['general_track'].values[0] == 0:
|
|
if df['general_track'].values[0] == 0:
|
|
- needed_app_id_cnt = video_cnt
|
|
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
- random.shuffle(app_id_array)
|
|
|
|
- app_id_cnt = 0
|
|
|
|
- for app_id in app_id_array:
|
|
|
|
- campaign_id = None
|
|
|
|
- # 1、获取该 app_id 的应该详情
|
|
|
|
- app_id_info = get_app_detail(account_id=account_id,
|
|
|
|
- url=get_app_detail_url,
|
|
|
|
- app_id=app_id)
|
|
|
|
- if app_id_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 2、依据 appVersion 的值,来判断当天是否已经有对应的计划,如果有则获取 campaign_id, 没有则设置 campaign_name
|
|
|
|
- app_version = app_id_info['data'].get('appVersion', 'error')
|
|
|
|
- track_url = app_id_info['data'].get('trackUrl', 'error')
|
|
|
|
-
|
|
|
|
- sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
- where account_id = %s""" % account_id
|
|
|
|
- campaign_df = pd.read_sql(sql, engine)
|
|
|
|
- for row in campaign_df.itertuples():
|
|
|
|
- if (app_version + '--优选广告位-' + '高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
- campaign_id = getattr(row, 'campaign_id')
|
|
|
|
- break
|
|
|
|
-
|
|
|
|
- # 3、获取app_id对应的1个视频
|
|
|
|
- special_video_info = get_top_video_info(account_id=account_id,
|
|
|
|
- url=get_high_quality_video_url,
|
|
|
|
- start_time=(now + datetime.timedelta(days=-2*high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- end_time=(now + datetime.timedelta(days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- cnt=1,
|
|
|
|
- app_version=app_version)
|
|
|
|
- if special_video_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 6、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
- # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
- # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
|
|
- request_data = get_request_data(account_id=account_id,
|
|
|
|
- campaign_id=campaign_id,
|
|
|
|
- video_info=special_video_info['data'],
|
|
|
|
- campaign_name=app_version + '--优选广告位-' + '高质量素材',
|
|
|
|
- group_name=app_version + '-优选广告位-不限-自定义-' + '高质量素材',
|
|
|
|
- ai_strategy_remark="用高质量素材补满创意",
|
|
|
|
- unit_type=4,
|
|
|
|
- app_id=app_id,
|
|
|
|
- click_track_url=track_url)
|
|
|
|
- request = ai_strategy_request_parse(request_data)
|
|
|
|
- logger.info("account_id=%s, app_id=%s, 用高质量素材补满创意,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
- app_id_cnt += 1
|
|
|
|
- if app_id_cnt >= needed_app_id_cnt:
|
|
|
|
- break
|
|
|
|
- self.write(json.dumps({"message": "account_id=%s, 多应用的高质量素材补满创意的请求已走完!" % account_id}))
|
|
|
|
- self.flush()
|
|
|
|
|
|
+ app_list = get_app_list(account_id=account_id, url=get_app_list_url)
|
|
|
|
+ # app_dict key = ("appVersion": "ksjyrlyn-人类一脑涂地大败") , value = 完整的app_id信息
|
|
|
|
+ app_dict = {}
|
|
|
|
+ for app_info in app_list['data']:
|
|
|
|
+ if app_info['appId'] in app_id_array:
|
|
|
|
+ app_dict[app_info['appVersion']] = app_info
|
|
|
|
+ video_list = get_top_video_info(account_id=account_id,
|
|
|
|
+ url=get_high_quality_video_url,
|
|
|
|
+ start_time=(now + datetime.timedelta(days=-2*high_quality_video_days)).
|
|
|
|
+ strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ end_time=(now + datetime.timedelta(days=-high_quality_video_days)).
|
|
|
|
+ strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ cnt=video_cnt,
|
|
|
|
+ app_version=None)
|
|
|
|
+
|
|
|
|
+ # 单独处理返回的时候中,有通用视频,需要单独处理
|
|
|
|
+ # "photo_name": "all",
|
|
|
|
+ # "photo_name": "ksjytdrca-糖豆人冲啊",
|
|
|
|
+ if video_list['code'] == 0:
|
|
|
|
+ video_df = pd.DataFrame(video_list['data'])
|
|
|
|
+ # 1-特定视频的创建
|
|
|
|
+ special_video_df = video_df[video_df.photo_name != 'all']
|
|
|
|
+ for photo_name in special_video_df['photo_name'].unique():
|
|
|
|
+ if photo_name in app_dict.keys():
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[photo_name].get('appId', 'error')
|
|
|
|
+ app_version = app_dict[photo_name].get('appVersion', 'error')
|
|
|
|
+ track_url = app_dict[photo_name].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ app_id_video_df = special_video_df[special_video_df.photo_name == photo_name]
|
|
|
|
+ app_id_video_list = []
|
|
|
|
+ for k, v in app_id_video_df.T.to_dict().items():
|
|
|
|
+ app_id_video_list.append(v)
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=app_id_video_list,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '高质量素材',
|
|
|
|
+ ai_strategy_remark="用高质量素材补满创意",
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 用高质量素材补满创意-特定视频,ai策略的返回信息:%s" %
|
|
|
|
+ (account_id, app_id, request))
|
|
|
|
+
|
|
|
|
+ # 2-通用视频的创建,random.shuffle 选择 app_id
|
|
|
|
+ general_video_df = video_df[video_df.photo_name == 'all']
|
|
|
|
+ if not general_video_df.empty:
|
|
|
|
+ general_video_cnt = len(general_video_df)
|
|
|
|
+ app_version_list = list(app_dict)
|
|
|
|
+ random.shuffle(app_version_list)
|
|
|
|
+ video_cnt = 0
|
|
|
|
+ for app_version in app_version_list[:general_video_cnt]:
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[app_version].get('appId', 'error')
|
|
|
|
+ track_url = app_dict[app_version].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ single_video = [general_video_df.iloc[video_cnt, :].T.to_dict()]
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=single_video,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '高质量素材',
|
|
|
|
+ ai_strategy_remark="用高质量素材补满创意",
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ video_cnt += 1
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 用高质量素材补满创意-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+ else:
|
|
|
|
+ logger.info("account_id=%s, 用高质量素材补满创意: 返回的视频中没有通用视频" % account_id)
|
|
|
|
+ self.write(json.dumps({"message": "account_id=%s, 用高质量素材补满创意请求已走完!" % account_id}))
|
|
|
|
+ self.flush()
|
|
else:
|
|
else:
|
|
# 1-1 获取当天计划中包含“高质量素材”计划的,计划id
|
|
# 1-1 获取当天计划中包含“高质量素材”计划的,计划id
|
|
sql = """
|
|
sql = """
|
|
@@ -532,8 +617,10 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
|
|
|
|
|
|
video_info = get_top_video_info(account_id=account_id,
|
|
video_info = get_top_video_info(account_id=account_id,
|
|
cnt=video_cnt,
|
|
cnt=video_cnt,
|
|
- start_time=(now + datetime.timedelta(days=-2*high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- end_time=(now + datetime.timedelta(days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
|
|
+ start_time=(now + datetime.timedelta(days=-2*high_quality_video_days)).
|
|
|
|
+ strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ end_time=(now + datetime.timedelta(days=-high_quality_video_days)).
|
|
|
|
+ strftime("%Y-%m-%d %H:%M:%S"),
|
|
url=get_high_quality_video_url)
|
|
url=get_high_quality_video_url)
|
|
if video_info['code'] != 0:
|
|
if video_info['code'] != 0:
|
|
logger.info("account_id = %s, 历史高质量素材填满, 没有获取到视频,不发送ai策略请求!" % account_id)
|
|
logger.info("account_id = %s, 历史高质量素材填满, 没有获取到视频,不发送ai策略请求!" % account_id)
|
|
@@ -603,61 +690,121 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
|
|
df = pd.read_sql(sql, engine)
|
|
df = pd.read_sql(sql, engine)
|
|
if df['general_track'].values[0] == 0:
|
|
if df['general_track'].values[0] == 0:
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
- random.shuffle(app_id_array)
|
|
|
|
- app_id_cnt = 0
|
|
|
|
- for app_id in app_id_array:
|
|
|
|
- campaign_id = None
|
|
|
|
- # 1、获取该 app_id 的应该详情
|
|
|
|
- app_id_info = get_app_detail(account_id=account_id,
|
|
|
|
- url=get_app_detail_url,
|
|
|
|
- app_id=app_id)
|
|
|
|
- if app_id_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 2、依据 appVersion 的值,来判断是否已经有对应的计划,如果有则获取 campaign_id,没有则设置 campaign_name
|
|
|
|
- sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
- where account_id = %s """ % account_id
|
|
|
|
- campaign_df = pd.read_sql(sql, engine)
|
|
|
|
- for row in campaign_df.itertuples():
|
|
|
|
- if (app_version + '--优选广告位-' + '程序化高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
- campaign_id = getattr(row, 'campaign_id')
|
|
|
|
- break
|
|
|
|
-
|
|
|
|
- app_version = app_id_info['data'].get('appVersion', 'error')
|
|
|
|
- track_url = app_id_info['data'].get('trackUrl', 'error')
|
|
|
|
-
|
|
|
|
- # 2、获取特定视频
|
|
|
|
- special_video_info = get_top_video_info(account_id=account_id,
|
|
|
|
- url=get_high_quality_video_url,
|
|
|
|
- start_time=(datetime.datetime.now() +
|
|
|
|
- datetime.timedelta(days=-high_quality_video_days)).
|
|
|
|
- strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- cnt=5,
|
|
|
|
- app_version=app_version)
|
|
|
|
- if special_video_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 3、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
- # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
- # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
|
|
- request_data = get_request_data(account_id=account_id,
|
|
|
|
- campaign_id=campaign_id,
|
|
|
|
- video_info=special_video_info['data'],
|
|
|
|
- campaign_name=app_version + '--优选广告位-' + '程序化高质量素材',
|
|
|
|
- group_name=app_version + '-优选广告位-不限-程序化-' + '高质量素材',
|
|
|
|
- ai_strategy_remark="程序化高质量素材",
|
|
|
|
- unit_type=7,
|
|
|
|
- app_id=app_id,
|
|
|
|
- click_track_url=track_url)
|
|
|
|
- request = ai_strategy_request_parse(request_data)
|
|
|
|
- logger.info("account_id=%s, app_id=%s, 程序化高质量素材,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
- app_id_cnt += 1
|
|
|
|
- if app_id_cnt >= 30:
|
|
|
|
- break
|
|
|
|
|
|
+ app_list = get_app_list(account_id=account_id, url=get_app_list_url)
|
|
|
|
+ # app_dict key = ("appVersion": "ksjyrlyn-人类一脑涂地大败") , value = 完整的app_id信息
|
|
|
|
+ app_dict = {}
|
|
|
|
+ for app_info in app_list['data']:
|
|
|
|
+ if app_info['appId'] in app_id_array:
|
|
|
|
+ app_dict[app_info['appVersion']] = app_info
|
|
|
|
+ video_list = get_top_video_info(account_id=account_id,
|
|
|
|
+ cnt=multi_app_id_programme_high_quality_video_cnt,
|
|
|
|
+ start_time=(datetime.datetime.now() + datetime.timedelta(
|
|
|
|
+ days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ url=get_high_quality_video_url)
|
|
|
|
|
|
- self.write(json.dumps({"message": "account_id=%s, 多应用的高质量素材程序化创意的请求已走完!" % account_id}))
|
|
|
|
- self.flush()
|
|
|
|
|
|
+ # 单独处理返回的时候中,有通用视频,需要单独处理
|
|
|
|
+ # "photo_name": "all",
|
|
|
|
+ # "photo_name": "ksjytdrca-糖豆人冲啊",
|
|
|
|
+ if video_list['code'] == 0:
|
|
|
|
+ video_df = pd.DataFrame(video_list['data'])
|
|
|
|
+ # 1-特定视频的创建
|
|
|
|
+ special_video_df = video_df[video_df.photo_name != 'all']
|
|
|
|
+ for photo_name in special_video_df['photo_name'].unique():
|
|
|
|
+ if photo_name in app_dict.keys():
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[photo_name].get('appId', 'error')
|
|
|
|
+ app_version = app_dict[photo_name].get('appVersion', 'error')
|
|
|
|
+ track_url = app_dict[photo_name].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '程序化高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ app_id_video_df = special_video_df[special_video_df.photo_name == photo_name]
|
|
|
|
+ app_id_video_list = []
|
|
|
|
+ for k, v in app_id_video_df.T.to_dict().items():
|
|
|
|
+ app_id_video_list.append(v)
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=app_id_video_list,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '程序化高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-程序化-' + '高质量素材',
|
|
|
|
+ ai_strategy_remark="程序化高质量素材",
|
|
|
|
+ unit_type=7,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 程序化高质量素材-特定视频,ai策略的返回信息:%s" %
|
|
|
|
+ (account_id, app_id, request))
|
|
|
|
+
|
|
|
|
+ # 2-通用视频的创建,random.shuffle 选择 app_id
|
|
|
|
+ general_video_df = video_df[video_df.photo_name == 'all']
|
|
|
|
+ general_video_list = []
|
|
|
|
+ for k, v in general_video_df.T.to_dict().items():
|
|
|
|
+ general_video_list.append(v)
|
|
|
|
+ if general_video_list:
|
|
|
|
+ app_version_list = list(app_dict)
|
|
|
|
+ random.shuffle(app_version_list)
|
|
|
|
+ # 每5个通用视频创建一个程序化广告组
|
|
|
|
+ batch_num = 5
|
|
|
|
+ app_id_cnt = 0
|
|
|
|
+ for i in range(0, len(general_video_list), 5):
|
|
|
|
+ if i + 5 < len(general_video_list):
|
|
|
|
+ batch_general_video = general_video_list[i: i+batch_num]
|
|
|
|
+ app_version = app_version_list[app_id_cnt]
|
|
|
|
+ app_id = app_dict[app_version].get('appId', 'error')
|
|
|
|
+ track_url = app_dict[app_version].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '程序化高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=batch_general_video,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '程序化高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-程序化-' + '高质量素材',
|
|
|
|
+ ai_strategy_remark="程序化高质量素材",
|
|
|
|
+ unit_type=7,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ app_id_cnt += 1
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 程序化高质量素材-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+ else:
|
|
|
|
+ batch_general_video = general_video_list[i: len(general_video_list)]
|
|
|
|
+ app_version = app_version_list[app_id_cnt]
|
|
|
|
+ app_id = app_dict[app_version].get('appId', 'error')
|
|
|
|
+ track_url = app_dict[app_version].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '程序化高质量素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=batch_general_video,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '程序化高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-程序化-' + '高质量素材',
|
|
|
|
+ ai_strategy_remark="程序化高质量素材",
|
|
|
|
+ unit_type=7,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 程序化高质量素材-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+ else:
|
|
|
|
+ logger.info("account_id=%s, 程序化高质量素材: 返回的视频中没有通用视频" % account_id)
|
|
|
|
+ self.write(json.dumps({"message": "account_id=%s, 程序化高质量素材请求已走完!" % account_id}))
|
|
|
|
+ self.flush()
|
|
else:
|
|
else:
|
|
video_info = get_top_video_info(account_id=account_id,
|
|
video_info = get_top_video_info(account_id=account_id,
|
|
cnt=programme_high_quality_video_cnt,
|
|
cnt=programme_high_quality_video_cnt,
|
|
@@ -718,62 +865,120 @@ class AiProgramCreativeNewMaterial(tornado.web.RequestHandler):
|
|
df = pd.read_sql(sql, engine)
|
|
df = pd.read_sql(sql, engine)
|
|
if df['general_track'].values[0] == 0:
|
|
if df['general_track'].values[0] == 0:
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
app_id_array = eval(df['app_id_array'].values[0])
|
|
- random.shuffle(app_id_array)
|
|
|
|
- app_id_cnt = 0
|
|
|
|
- for app_id in app_id_array:
|
|
|
|
- campaign_id = None
|
|
|
|
- # 1、获取该 app_id 的应该详情
|
|
|
|
- app_id_info = get_app_detail(account_id=account_id,
|
|
|
|
- url=get_app_detail_url,
|
|
|
|
- app_id=app_id)
|
|
|
|
- if app_id_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 2、依据 appVersion 的值,来判断是否已经有对应的计划,如果有则获取 campaign_id,没有则设置 campaign_name
|
|
|
|
- sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
- where account_id = %s """ % account_id
|
|
|
|
- campaign_df = pd.read_sql(sql, engine)
|
|
|
|
- for row in campaign_df.itertuples():
|
|
|
|
- if (app_version + '--优选广告位-' + '程序化上新素材') == getattr(row, 'campaign_name'):
|
|
|
|
- campaign_id = getattr(row, 'campaign_id')
|
|
|
|
- break
|
|
|
|
-
|
|
|
|
- app_version = app_id_info['data'].get('appVersion', 'error')
|
|
|
|
- track_url = app_id_info['data'].get('trackUrl', 'error')
|
|
|
|
-
|
|
|
|
- # 2、获取特定视频
|
|
|
|
- special_video_info = get_history_video_info(account_id=account_id,
|
|
|
|
- url=get_history_video_url,
|
|
|
|
- start_time=(datetime.datetime.now() + datetime.timedelta(days=-60)).
|
|
|
|
- strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
- video_cnt=5,
|
|
|
|
- related_creative_max_cnt=related_creative_max_cnt,
|
|
|
|
- app_version=app_version
|
|
|
|
- )
|
|
|
|
- if special_video_info['code'] != 0:
|
|
|
|
- continue
|
|
|
|
-
|
|
|
|
- # 3、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
- # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
- # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
|
|
- request_data = get_request_data(account_id=account_id,
|
|
|
|
- campaign_id=campaign_id,
|
|
|
|
- video_info=special_video_info['data'],
|
|
|
|
- campaign_name=app_version + '--优选广告位-' + '程序化上新素材',
|
|
|
|
- group_name=app_version + '-优选广告位-不限-程序化-' + '上新素材',
|
|
|
|
- ai_strategy_remark="程序化上新素材",
|
|
|
|
- unit_type=7,
|
|
|
|
- app_id=app_id,
|
|
|
|
- click_track_url=track_url)
|
|
|
|
- request = ai_strategy_request_parse(request_data)
|
|
|
|
- logger.info("account_id=%s, app_id=%s, 程序化上新素材,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
- app_id_cnt += 1
|
|
|
|
- if app_id_cnt >= 30:
|
|
|
|
- break
|
|
|
|
|
|
+ app_list = get_app_list(account_id=account_id, url=get_app_list_url)
|
|
|
|
+ # app_dict key = ("appVersion": "ksjyrlyn-人类一脑涂地大败") , value = 完整的app_id信息
|
|
|
|
+ app_dict = {}
|
|
|
|
+ for app_info in app_list['data']:
|
|
|
|
+ if app_info['appId'] in app_id_array:
|
|
|
|
+ app_dict[app_info['appVersion']] = app_info
|
|
|
|
+ video_list = get_history_video_info(account_id=account_id,
|
|
|
|
+ url=get_history_video_url,
|
|
|
|
+ start_time=(datetime.datetime.now() + datetime.timedelta(days=-7)).
|
|
|
|
+ strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ video_cnt=multi_app_id_programme_new_video_cnt,
|
|
|
|
+ related_creative_max_cnt=related_creative_max_cnt)
|
|
|
|
|
|
- self.write(json.dumps({"message": "account_id=%s, 多应用的上新素材程序化创意的请求已走完!" % account_id}))
|
|
|
|
- self.flush()
|
|
|
|
|
|
+ # 单独处理返回的时候中,有通用视频,需要单独处理
|
|
|
|
+ # "photo_name": "all",
|
|
|
|
+ # "photo_name": "ksjytdrca-糖豆人冲啊",
|
|
|
|
+ if video_list['code'] == 0:
|
|
|
|
+ video_df = pd.DataFrame(video_list['data'])
|
|
|
|
+ # 1-特定视频的创建
|
|
|
|
+ special_video_df = video_df[video_df.photo_name != 'all']
|
|
|
|
+ for photo_name in special_video_df['photo_name'].unique():
|
|
|
|
+ if photo_name in app_dict.keys():
|
|
|
|
+ campaign_id = None
|
|
|
|
+ app_id = app_dict[photo_name].get('appId', 'error')
|
|
|
|
+ app_version = app_dict[photo_name].get('appVersion', 'error')
|
|
|
|
+ track_url = app_dict[photo_name].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '程序化上新素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+ app_id_video_df = special_video_df[special_video_df.photo_name == photo_name]
|
|
|
|
+ app_id_video_list = []
|
|
|
|
+ for k, v in app_id_video_df.T.to_dict().items():
|
|
|
|
+ app_id_video_list.append(v)
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=app_id_video_list,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '程序化上新素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-程序化-' + '上新素材',
|
|
|
|
+ ai_strategy_remark="程序化上新素材",
|
|
|
|
+ unit_type=7,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 程序化上新素材-特定视频,ai策略的返回信息:%s" %
|
|
|
|
+ (account_id, app_id, request))
|
|
|
|
+
|
|
|
|
+ # 2-通用视频的创建,random.shuffle 选择 app_id
|
|
|
|
+ general_video_df = video_df[video_df.photo_name == 'all']
|
|
|
|
+ general_video_list = []
|
|
|
|
+ for k, v in general_video_df.T.to_dict().items():
|
|
|
|
+ general_video_list.append(v)
|
|
|
|
+ if general_video_list:
|
|
|
|
+ app_version_list = list(app_dict)
|
|
|
|
+ random.shuffle(app_version_list)
|
|
|
|
+ # 每5个通用视频创建一个程序化广告组
|
|
|
|
+ batch_num = 5
|
|
|
|
+ app_id_cnt = 0
|
|
|
|
+ for i in range(0, len(general_video_list), 5):
|
|
|
|
+ if i + 5 < len(general_video_list):
|
|
|
|
+ batch_general_video = general_video_list[i: i + batch_num]
|
|
|
|
+ app_version = app_version_list[app_id_cnt]
|
|
|
|
+ app_id = app_dict[app_version].get('appId', 'error')
|
|
|
|
+ track_url = app_dict[app_version].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '程序化上新素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=batch_general_video,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '程序化上新素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-程序化-' + '上新素材',
|
|
|
|
+ ai_strategy_remark="程序化上新素材",
|
|
|
|
+ unit_type=7,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ app_id_cnt += 1
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 程序化上新素材-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+ else:
|
|
|
|
+ batch_general_video = general_video_list[i: len(general_video_list)]
|
|
|
|
+ app_version = app_version_list[app_id_cnt]
|
|
|
|
+ app_id = app_dict[app_version].get('appId', 'error')
|
|
|
|
+ track_url = app_dict[app_version].get('trackUrl', 'error')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign where account_id = %s """ % account_id
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if (app_version + '--优选广告位-' + '程序化上新素材') == getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=batch_general_video,
|
|
|
|
+ campaign_name=app_version + '--优选广告位-' + '程序化上新素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-程序化-' + '上新素材',
|
|
|
|
+ ai_strategy_remark="程序化上新素材",
|
|
|
|
+ unit_type=7,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+
|
|
|
|
+ logger.info("account_id=%s, app_id=%s, 程序化上新素材-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
|
|
+ else:
|
|
|
|
+ logger.info("account_id=%s, 程序化上新素材: 返回的视频中没有通用视频" % account_id)
|
|
|
|
+ self.write(json.dumps({"message": "account_id=%s, 程序化上新素材请求已走完!" % account_id}))
|
|
|
|
+ self.flush()
|
|
else:
|
|
else:
|
|
video_info = get_history_video_info(account_id=account_id,
|
|
video_info = get_history_video_info(account_id=account_id,
|
|
url=get_history_video_url,
|
|
url=get_history_video_url,
|