|
@@ -2,6 +2,7 @@ import datetime
|
|
import json
|
|
import json
|
|
import uuid
|
|
import uuid
|
|
from logging.handlers import TimedRotatingFileHandler
|
|
from logging.handlers import TimedRotatingFileHandler
|
|
|
|
+from concurrent_log import ConcurrentTimedRotatingFileHandler
|
|
import pandas as pd
|
|
import pandas as pd
|
|
import pymysql
|
|
import pymysql
|
|
import requests
|
|
import requests
|
|
@@ -10,8 +11,9 @@ from utils.UrlConfig import *
|
|
import logging
|
|
import logging
|
|
|
|
|
|
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', '%m/%d/%Y %I:%M:%S %p')
|
|
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', '%m/%d/%Y %I:%M:%S %p')
|
|
-log_handler = TimedRotatingFileHandler("logs/ai_strategy_request.log",
|
|
|
|
- when="midnight", backupCount=100)
|
|
|
|
|
|
+# log_handler = TimedRotatingFileHandler("logs/ai_strategy_request.log",
|
|
|
|
+# when="midnight", backupCount=100)
|
|
|
|
+log_handler = ConcurrentTimedRotatingFileHandler("logs/ai_strategy_request.log", when="midnight", backupCount=100)
|
|
log_handler.setFormatter(log_formatter)
|
|
log_handler.setFormatter(log_formatter)
|
|
logger = logging.getLogger('ai_strategy_request_logger')
|
|
logger = logging.getLogger('ai_strategy_request_logger')
|
|
logger.addHandler(log_handler)
|
|
logger.addHandler(log_handler)
|
|
@@ -206,29 +208,34 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
'sticker_title', 'overlay_type', 'expose_tag', 'new_expose_tag', 'site_id',
|
|
'sticker_title', 'overlay_type', 'expose_tag', 'new_expose_tag', 'site_id',
|
|
'click_track_url', 'impression_url', 'ad_photo_played_t3s_url', 'actionbar_click_url',
|
|
'click_track_url', 'impression_url', 'ad_photo_played_t3s_url', 'actionbar_click_url',
|
|
'creative_category', 'creative_tag', 'image_cnt',
|
|
'creative_category', 'creative_tag', 'image_cnt',
|
|
- 'create_time', 'effective_time', 'expiry_time', 'timer_task_status', 'smart_cover', 'asset_mining']
|
|
|
|
|
|
+ 'create_time', 'effective_time', 'expiry_time', 'timer_task_status']
|
|
for col in drop_cols:
|
|
for col in drop_cols:
|
|
if col in group_params.keys():
|
|
if col in group_params.keys():
|
|
del group_params[col]
|
|
del group_params[col]
|
|
|
|
|
|
|
|
+
|
|
# 2 从请求的信息中更新组层级信息, 如组的名称、测试定向、测试出价等, update客户策略信息
|
|
# 2 从请求的信息中更新组层级信息, 如组的名称、测试定向、测试出价等, update客户策略信息
|
|
if (self.group_info is not None) and (len(self.group_info) > 0):
|
|
if (self.group_info is not None) and (len(self.group_info) > 0):
|
|
for key, value in self.group_info.items():
|
|
for key, value in self.group_info.items():
|
|
group_params.update({key: value})
|
|
group_params.update({key: value})
|
|
|
|
|
|
- # 3 拼装json的组参数
|
|
|
|
|
|
+ # 3 smart_cover 和 asset_mining 需要将0/1 转化为 False/True
|
|
|
|
+ group_params['smart_cover'] = True if group_params.get('smart_cover', 0) == 1 else False
|
|
|
|
+ group_params['asset_mining'] = True if group_params.get('asset_mining', 0) == 1 else False
|
|
|
|
+
|
|
|
|
+ # 4 拼装json的组参数
|
|
group_params_to_request = group_params.copy()
|
|
group_params_to_request = group_params.copy()
|
|
- # 3-1 拼接发送请求json时, 以下字段需要转为 list 类型
|
|
|
|
|
|
+ # 4-1 拼接发送请求json时, 以下字段需要转为 list 类型
|
|
cols_to_list = ['app_store', 'scene_id', 'region', 'district_ids', 'ages_range', 'device_brand',
|
|
cols_to_list = ['app_store', 'scene_id', 'region', 'district_ids', 'ages_range', 'device_brand',
|
|
'device_price', 'business_interest', 'fans_star', 'interest_video', 'app_interest',
|
|
'device_price', 'business_interest', 'fans_star', 'interest_video', 'app_interest',
|
|
'app_ids', 'population', 'exclude_population', 'paid_audience', 'behavior_interest']
|
|
'app_ids', 'population', 'exclude_population', 'paid_audience', 'behavior_interest']
|
|
for col in cols_to_list:
|
|
for col in cols_to_list:
|
|
group_params_to_request[col] = eval(group_params_to_request[col]) \
|
|
group_params_to_request[col] = eval(group_params_to_request[col]) \
|
|
if ((group_params_to_request[col] is not None) and (group_params_to_request[col] != '')) else None
|
|
if ((group_params_to_request[col] is not None) and (group_params_to_request[col] != '')) else None
|
|
- # 3-2 发送请求,需要将 group_name 改为 unit_name
|
|
|
|
|
|
+ # 4-2 发送请求,需要将 group_name 改为 unit_name
|
|
group_params_to_request['unit_name'] = group_params_to_request.pop('group_name')
|
|
group_params_to_request['unit_name'] = group_params_to_request.pop('group_name')
|
|
|
|
|
|
- # 4 写入数据库的组参数
|
|
|
|
|
|
+ # 5 写入数据库的组参数
|
|
group_params_to_db = group_params.copy()
|
|
group_params_to_db = group_params.copy()
|
|
group_params_to_db['ai_strategy_uuid'] = self.ai_strategy_uuid
|
|
group_params_to_db['ai_strategy_uuid'] = self.ai_strategy_uuid
|
|
group_params_to_db['account_id'] = self.account_id
|
|
group_params_to_db['account_id'] = self.account_id
|
|
@@ -277,7 +284,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
# 1 从客户策略表中获取 创意层级基本信息
|
|
# 1 从客户策略表中获取 创意层级基本信息
|
|
creative_cols = ['creative_name', 'action_bar_text', 'description', 'site_id',
|
|
creative_cols = ['creative_name', 'action_bar_text', 'description', 'site_id',
|
|
'click_track_url', 'actionbar_click_url',
|
|
'click_track_url', 'actionbar_click_url',
|
|
- 'creative_category', 'creative_tag', 'smart_cover', 'asset_mining']
|
|
|
|
|
|
+ 'creative_category', 'creative_tag']
|
|
creative_params = {}
|
|
creative_params = {}
|
|
for col in creative_cols:
|
|
for col in creative_cols:
|
|
creative_params[col] = self.advertiser_strategy.get(col)
|
|
creative_params[col] = self.advertiser_strategy.get(col)
|
|
@@ -397,6 +404,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
# 每5个视频一组,来拼接组层级 和 程序化创意 层级的参数
|
|
# 每5个视频一组,来拼接组层级 和 程序化创意 层级的参数
|
|
self.res_data['group_list'] = []
|
|
self.res_data['group_list'] = []
|
|
cnt = 1
|
|
cnt = 1
|
|
|
|
+ is_smart_cover = group_params_to_request.get('smart_cover', 0)
|
|
for i in range(0, len(self.video), 5):
|
|
for i in range(0, len(self.video), 5):
|
|
group_uuid = str(uuid.uuid4())
|
|
group_uuid = str(uuid.uuid4())
|
|
group_name = group_params_to_db['group_name'] + '-' + str(cnt)
|
|
group_name = group_params_to_db['group_name'] + '-' + str(cnt)
|
|
@@ -431,6 +439,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
if self.video[j]['material_type'] == 1:
|
|
if self.video[j]['material_type'] == 1:
|
|
vertical_photo_ids.append(self.video[j]['photo_id'])
|
|
vertical_photo_ids.append(self.video[j]['photo_id'])
|
|
cover_image_tokens.append(self.video[j]['imageList'][0])
|
|
cover_image_tokens.append(self.video[j]['imageList'][0])
|
|
|
|
+
|
|
if len(cover_image_tokens) >= 5:
|
|
if len(cover_image_tokens) >= 5:
|
|
cover_image_tokens = cover_image_tokens[:4]
|
|
cover_image_tokens = cover_image_tokens[:4]
|
|
|
|
|
|
@@ -441,7 +450,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
single_creative_params_to_db['package_name'] = package_name
|
|
single_creative_params_to_db['package_name'] = package_name
|
|
single_creative_params_to_db['horizontal_photo_ids'] = str(horizontal_photo_ids)
|
|
single_creative_params_to_db['horizontal_photo_ids'] = str(horizontal_photo_ids)
|
|
single_creative_params_to_db['vertical_photo_ids'] = str(vertical_photo_ids)
|
|
single_creative_params_to_db['vertical_photo_ids'] = str(vertical_photo_ids)
|
|
- single_creative_params_to_db['cover_image_tokens'] = str(cover_image_tokens)
|
|
|
|
|
|
+ single_creative_params_to_db['cover_image_tokens'] = str(cover_image_tokens) if not is_smart_cover else None
|
|
single_creative_params_to_db['create_time'] = datetime.datetime.now()
|
|
single_creative_params_to_db['create_time'] = datetime.datetime.now()
|
|
df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
|
|
df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
|
|
df.to_sql(name="ctop_ai_kuaishou_program_creative_level_operation_record",
|
|
df.to_sql(name="ctop_ai_kuaishou_program_creative_level_operation_record",
|
|
@@ -454,7 +463,9 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
single_creative_params_to_request['package_name'] = package_name
|
|
single_creative_params_to_request['package_name'] = package_name
|
|
single_creative_params_to_request['horizontal_photo_ids'] = horizontal_photo_ids
|
|
single_creative_params_to_request['horizontal_photo_ids'] = horizontal_photo_ids
|
|
single_creative_params_to_request['vertical_photo_ids'] = vertical_photo_ids
|
|
single_creative_params_to_request['vertical_photo_ids'] = vertical_photo_ids
|
|
- single_creative_params_to_request['image_md5s'] = cover_image_tokens
|
|
|
|
|
|
+ if not is_smart_cover:
|
|
|
|
+ single_creative_params_to_request['image_md5s'] = cover_image_tokens
|
|
|
|
+
|
|
else:
|
|
else:
|
|
# material_type=1 竖版
|
|
# material_type=1 竖版
|
|
# material_type=2 横版
|
|
# material_type=2 横版
|
|
@@ -475,7 +486,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
single_creative_params_to_db['package_name'] = package_name
|
|
single_creative_params_to_db['package_name'] = package_name
|
|
single_creative_params_to_db['horizontal_photo_ids'] = str(horizontal_photo_ids)
|
|
single_creative_params_to_db['horizontal_photo_ids'] = str(horizontal_photo_ids)
|
|
single_creative_params_to_db['vertical_photo_ids'] = str(vertical_photo_ids)
|
|
single_creative_params_to_db['vertical_photo_ids'] = str(vertical_photo_ids)
|
|
- single_creative_params_to_db['cover_image_tokens'] = str(cover_image_tokens)
|
|
|
|
|
|
+ single_creative_params_to_db['cover_image_tokens'] = str(cover_image_tokens) if not is_smart_cover else None
|
|
single_creative_params_to_db['create_time'] = datetime.datetime.now()
|
|
single_creative_params_to_db['create_time'] = datetime.datetime.now()
|
|
df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
|
|
df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
|
|
df.to_sql(name="ctop_ai_kuaishou_program_creative_level_operation_record",
|
|
df.to_sql(name="ctop_ai_kuaishou_program_creative_level_operation_record",
|
|
@@ -488,7 +499,8 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
single_creative_params_to_request['package_name'] = package_name
|
|
single_creative_params_to_request['package_name'] = package_name
|
|
single_creative_params_to_request['horizontal_photo_ids'] = horizontal_photo_ids
|
|
single_creative_params_to_request['horizontal_photo_ids'] = horizontal_photo_ids
|
|
single_creative_params_to_request['vertical_photo_ids'] = vertical_photo_ids
|
|
single_creative_params_to_request['vertical_photo_ids'] = vertical_photo_ids
|
|
- single_creative_params_to_request['image_md5s'] = cover_image_tokens
|
|
|
|
|
|
+ if not is_smart_cover:
|
|
|
|
+ single_creative_params_to_request['image_md5s'] = cover_image_tokens
|
|
|
|
|
|
single_group_params_to_request['programCreative'] = single_creative_params_to_request
|
|
single_group_params_to_request['programCreative'] = single_creative_params_to_request
|
|
cnt += 1
|
|
cnt += 1
|