|
@@ -16,49 +16,37 @@ 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)
|
|
logger.setLevel(logging.DEBUG)
|
|
logger.setLevel(logging.DEBUG)
|
|
-print('id of logger %s' % id(logger))
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-class AiStrategyRequestParse(tornado.web.RequestHandler):
|
|
|
|
- def post(self):
|
|
|
|
- data = self.request.body
|
|
|
|
- data = str(data, 'utf8')
|
|
|
|
- data = json.loads(data, encoding='utf8')
|
|
|
|
- logger.info("*************************************** NEW REQUEST ***************************************")
|
|
|
|
- logger.info("raw data from request is %s" % data)
|
|
|
|
-
|
|
|
|
- # 1、新增广告组操作
|
|
|
|
- try:
|
|
|
|
- if data["operation_type"] == 1:
|
|
|
|
- inst = ParseAddCampaignOrAddGroupRequest(data)
|
|
|
|
- inst.get_advertiser_strategy_info()
|
|
|
|
- inst.write_intelligence_strategy_table()
|
|
|
|
- if inst.campaign_id == "" or inst.campaign_id is None:
|
|
|
|
- if inst.add_campaign() == -1:
|
|
|
|
- raise Exception('广告计划创建失败')
|
|
|
|
-
|
|
|
|
- inst.assemble_group_and_creative_params()
|
|
|
|
- create_group_and_creative_res = inst.res_data
|
|
|
|
- inst.update_intelligence_strategy_table()
|
|
|
|
- logger.info("create group and creative request info: %s" % create_group_and_creative_res)
|
|
|
|
-
|
|
|
|
- request = requests.post(create_group_and_creative_url,
|
|
|
|
- headers=headers,
|
|
|
|
- data=json.JSONEncoder().encode(create_group_and_creative_res)
|
|
|
|
- )
|
|
|
|
- create_group_and_creative_response_data = json.loads(request.text)
|
|
|
|
- logger.info("请求返回:%s" % create_group_and_creative_response_data)
|
|
|
|
- self.write(json.dumps({'account_id': inst.account_id,
|
|
|
|
- 'ai_strategy_id': inst.ai_strategy_uuid,
|
|
|
|
- 'message': create_group_and_creative_response_data}))
|
|
|
|
- self.flush()
|
|
|
|
- else:
|
|
|
|
- self.write(json.dumps({"message": "operation_type 不支持"}))
|
|
|
|
- self.flush()
|
|
|
|
- except Exception:
|
|
|
|
- logger.error(traceback.format_exc())
|
|
|
|
- self.write(json.dumps(traceback.format_exc()))
|
|
|
|
- self.flush()
|
|
|
|
|
|
+print('id of ai_strategy_request_logger %s' % id(logger))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def ai_strategy_request_parse(data):
|
|
|
|
+ """
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ :param data:
|
|
|
|
+ :return:
|
|
|
|
+ """
|
|
|
|
+ if data["operation_type"] == 1:
|
|
|
|
+ inst = ParseAddCampaignOrAddGroupRequest(data)
|
|
|
|
+ inst.get_advertiser_strategy_info()
|
|
|
|
+ inst.write_intelligence_strategy_table()
|
|
|
|
+ if inst.campaign_id == "" or inst.campaign_id is None:
|
|
|
|
+ if inst.add_campaign() == -1:
|
|
|
|
+ return {'code': -2, 'message': '广告计划创建失败!'}
|
|
|
|
+ inst.assemble_group_and_creative_params()
|
|
|
|
+ create_group_and_creative_res = inst.res_data
|
|
|
|
+ inst.update_intelligence_strategy_table()
|
|
|
|
+ logger.info("create group and creative request info: %s" % create_group_and_creative_res)
|
|
|
|
+
|
|
|
|
+ request = requests.post(create_group_and_creative_url,
|
|
|
|
+ headers=headers,
|
|
|
|
+ data=json.JSONEncoder().encode(create_group_and_creative_res)
|
|
|
|
+ )
|
|
|
|
+ response_data = json.loads(request.text)
|
|
|
|
+ logger.info("请求返回:%s" % response_data)
|
|
|
|
+ return {'code': 0, 'message': response_data}
|
|
|
|
+ else:
|
|
|
|
+ return {'code': -1, 'message': '暂时不支持非新增的操作请求!'}
|
|
|
|
|
|
|
|
|
|
# 该类解析的是 手动请求的新增广告计划或者新增广告组的数据
|
|
# 该类解析的是 手动请求的新增广告计划或者新增广告组的数据
|
|
@@ -187,14 +175,16 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
:return:
|
|
:return:
|
|
"""
|
|
"""
|
|
# 1、组层级基本信息
|
|
# 1、组层级基本信息
|
|
- drop_cols = ['id', 'account_id', 'status', 'campaign_type',
|
|
|
|
- 'site_id', 'click_track_url', 'impression_url', 'ad_photo_played_t3s_url',
|
|
|
|
- 'actionbar_click_url',
|
|
|
|
|
|
+ drop_cols = ['id', 'account_id', 'status', 'campaign_type', 'campaign_name', 'group_name',
|
|
|
|
+ 'creative_name', 'action_bar_text', 'description', 'short_slogan',
|
|
|
|
+ 'sticker_title', 'overlay_type', 'expose_tag', 'new_expose_tag', 'site_id',
|
|
|
|
+ 'click_track_url', 'impression_url', 'ad_photo_played_t3s_url', 'actionbar_click_url',
|
|
|
|
+ 'creative_category', 'creative_tag', 'image_cnt',
|
|
'create_time', 'effective_time', 'expiry_time']
|
|
'create_time', 'effective_time', 'expiry_time']
|
|
|
|
|
|
group_cols_to_list = ['app_store', 'scene_id', 'region', 'district_ids', 'ages_range', 'device_brand',
|
|
group_cols_to_list = ['app_store', 'scene_id', 'region', 'district_ids', 'ages_range', 'device_brand',
|
|
- 'device_price', 'business_interest', 'fans_star', 'interest_video', 'app_interest',
|
|
|
|
- 'app_ids', 'population', 'exclude_population', 'paid_audience', 'behavior_interest']
|
|
|
|
|
|
+ 'device_price', 'business_interest', 'fans_star', 'interest_video', 'app_interest',
|
|
|
|
+ 'app_ids', 'population', 'exclude_population', 'paid_audience', 'behavior_interest']
|
|
|
|
|
|
basic_group_info = self.advertiser_strategy.copy()
|
|
basic_group_info = self.advertiser_strategy.copy()
|
|
for col in drop_cols:
|
|
for col in drop_cols:
|
|
@@ -221,7 +211,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
# 2、创意层级基本信息
|
|
# 2、创意层级基本信息
|
|
creative_cols = ['creative_name', 'action_bar_text', 'description', 'short_slogan',
|
|
creative_cols = ['creative_name', 'action_bar_text', 'description', 'short_slogan',
|
|
'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']
|
|
'creative_category', 'creative_tag']
|
|
basic_creative_info = {}
|
|
basic_creative_info = {}
|
|
for col in creative_cols:
|
|
for col in creative_cols:
|
|
@@ -275,7 +265,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
|
|
creative_cnt = 1
|
|
creative_cnt = 1
|
|
for image_md5 in video['imageList'][: self.advertiser_strategy['image_cnt']]:
|
|
for image_md5 in video['imageList'][: self.advertiser_strategy['image_cnt']]:
|
|
creative_uuid = str(uuid.uuid4())
|
|
creative_uuid = str(uuid.uuid4())
|
|
- creative_name = self.creative_info['creative_name'] + '_' + str(creative_cnt)
|
|
|
|
|
|
+ creative_name = basic_creative_info['creative_name'] + '_' + str(creative_cnt)
|
|
|
|
|
|
single_creative_info_to_db = creative_info_to_db.copy()
|
|
single_creative_info_to_db = creative_info_to_db.copy()
|
|
single_creative_info_to_db['creative_uuid'] = creative_uuid
|
|
single_creative_info_to_db['creative_uuid'] = creative_uuid
|