|
@@ -40,35 +40,43 @@ class AiTargetCombine(tornado.web.RequestHandler):
|
|
|
try:
|
|
|
# 1、创建类实例
|
|
|
ins = GetTargetAndAssemblyParameters(account_id, project_id)
|
|
|
- # 2、判断当天是否已经存在包含【优质定向】的广告计划,如果有则获取该计划id,否则需要新建计划
|
|
|
- sql = """select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
- where account_id = %s
|
|
|
- and put_create_time >= curdate()
|
|
|
- and campaign_name like '%s'""" % (ins.account_id, '%%优质定向%%')
|
|
|
- df = pd.read_sql(sql, ins.engine)
|
|
|
- if df.empty:
|
|
|
- ins.add_campaign()
|
|
|
- else:
|
|
|
- ins.campaign_id = df['campaign_id'].values[0]
|
|
|
-
|
|
|
- # 3、拼装广告组和创意的参数
|
|
|
- ins.assembly_group_and_creative_params()
|
|
|
-
|
|
|
- # 4、信息写如到智能策略表中
|
|
|
- ins.write_intelligence_strategy_table()
|
|
|
-
|
|
|
- # 5、发送创建组和创意的请求
|
|
|
- request = requests.post(create_group_and_creative_url,
|
|
|
- headers=headers,
|
|
|
- data=json.dumps(ins.request_data, cls=NpEncoder))
|
|
|
- response_data = json.loads(request.text)
|
|
|
|
|
|
- # 6、接口的返回信息更新到数据库表
|
|
|
- ins.update_intelligence_strategy_table(message=response_data)
|
|
|
-
|
|
|
- logger.info("account_id = %s, 策略uuid = %s 的请求返回信息:%s" % (ins.account_id, ins.ai_strategy_uuid, response_data))
|
|
|
- self.write(json.dumps({"account_id": account_id, "message": str(response_data), "code": 1}))
|
|
|
- self.flush()
|
|
|
+ # 2、判断final_target_combine是否为空,为空则不执行后续的操作
|
|
|
+ if not ins.final_target_combine:
|
|
|
+ self.write(json.dumps({"account_id": account_id, "message": "没有合适的定向组合", "code": 1}))
|
|
|
+ self.flush()
|
|
|
+ else:
|
|
|
+ # 2、判断当天是否已经存在包含【优质定向】的广告计划,如果有则获取该计划id,否则需要新建计划
|
|
|
+ sql = """select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
+ where account_id = %s
|
|
|
+ and put_create_time >= curdate()
|
|
|
+ and campaign_name like '%s'""" % (ins.account_id, '%%优质定向%%')
|
|
|
+ df = pd.read_sql(sql, ins.engine)
|
|
|
+ if df.empty:
|
|
|
+ ins.add_campaign()
|
|
|
+ else:
|
|
|
+ ins.campaign_id = df['campaign_id'].values[0]
|
|
|
+
|
|
|
+ # 3、拼装广告组和创意的参数
|
|
|
+ ins.assembly_group_and_creative_params()
|
|
|
+
|
|
|
+ # 4、信息写如到智能策略表中
|
|
|
+ ins.write_intelligence_strategy_table()
|
|
|
+
|
|
|
+ # 5、
|
|
|
+
|
|
|
+ # 5、发送创建组和创意的请求
|
|
|
+ request = requests.post(create_group_and_creative_url,
|
|
|
+ headers=headers,
|
|
|
+ data=json.dumps(ins.request_data, cls=NpEncoder))
|
|
|
+ response_data = json.loads(request.text)
|
|
|
+
|
|
|
+ # 6、接口的返回信息更新到数据库表
|
|
|
+ ins.update_intelligence_strategy_table(message=response_data)
|
|
|
+
|
|
|
+ logger.info("account_id = %s, 策略uuid = %s 的请求返回信息:%s" % (ins.account_id, ins.ai_strategy_uuid, response_data))
|
|
|
+ self.write(json.dumps({"account_id": account_id, "message": str(response_data), "code": 1}))
|
|
|
+ self.flush()
|
|
|
except:
|
|
|
logger.error("account_id = %s, traceback is %s" % (account_id, traceback.format_exc()))
|
|
|
self.write(json.dumps({"account_id": account_id, "message": str(traceback.format_exc()), "code": -1}))
|
|
@@ -137,6 +145,7 @@ class GetTargetAndAssemblyParameters(object):
|
|
|
# 1、请求创建广告计划的接口
|
|
|
campaign_name = self.advertiser_strategy['campaign_name']
|
|
|
campaign_name = campaign_name.replace('{{自定义}}', '')
|
|
|
+ campaign_name = campaign_name.replace('{{日期}}', '')
|
|
|
campaign_name += '_优质定向_'
|
|
|
campaign_name += str(datetime.datetime.now().date())
|
|
|
create_campaign_request_data = {'account_id': self.account_id,
|