|
@@ -0,0 +1,65 @@
|
|
|
+import datetime
|
|
|
+import json
|
|
|
+import traceback
|
|
|
+import requests
|
|
|
+import tornado.web
|
|
|
+from db_config import *
|
|
|
+
|
|
|
+
|
|
|
+class AiHistoricalHighQualityMaterial(tornado.web.RequestHandler):
|
|
|
+ def initialize(self, logger):
|
|
|
+ self.logger = logger
|
|
|
+
|
|
|
+ def post(self):
|
|
|
+ self.logger.info("*************************************** NEW REQUEST ***************************************")
|
|
|
+ try:
|
|
|
+ for account_id in account_id_list:
|
|
|
+ inst = GetRequestData(account_id)
|
|
|
+ if inst.data is not None:
|
|
|
+ request = requests.post(ai_strategy_request_url, inst.data)
|
|
|
+ self.logger.info("ai策略的返回信息:%s" % request.text)
|
|
|
+ self.write(request.text)
|
|
|
+ self.flush()
|
|
|
+ else:
|
|
|
+ self.write(json.dumps({"message": "没有获取到视频新,不发送ai策略请求!"}))
|
|
|
+ self.flush()
|
|
|
+ except Exception:
|
|
|
+ self.logger.error(traceback.format_exc())
|
|
|
+ self.write(json.dumps(traceback.format_exc()))
|
|
|
+ self.flush()
|
|
|
+
|
|
|
+
|
|
|
+class GetRequestData(object):
|
|
|
+ def __init__(self, account_id):
|
|
|
+ self.video = None
|
|
|
+ self.account_id = account_id
|
|
|
+ self.data = None
|
|
|
+ self.get_video_info()
|
|
|
+ self.get_request_data()
|
|
|
+
|
|
|
+ def get_video_info(self):
|
|
|
+ video_request_data = {"accountId": self.account_id,
|
|
|
+ "videoCnt": historical_missing_video_cnt,
|
|
|
+ "days": high_quality_video_days
|
|
|
+ }
|
|
|
+ request = requests.post(get_historical_high_quality_video_url,
|
|
|
+ headers=headers,
|
|
|
+ data=json.JSONEncoder().encode(video_request_data))
|
|
|
+ self.video = request
|
|
|
+
|
|
|
+ def get_request_data(self):
|
|
|
+ if self.video['code'] == 0:
|
|
|
+ self.data = {"video": self.video['data'],
|
|
|
+ "operation_type": 1,
|
|
|
+ "account_id": self.account_id,
|
|
|
+ "ai_strategy_remark": "跑量素材",
|
|
|
+ "campaign_info": {
|
|
|
+ "campaign_id": "",
|
|
|
+ "campaign_name": account_id_to_name[self.account_id] +
|
|
|
+ campaign_name.replace('自定义', '跑量素材')
|
|
|
+ + str(datetime.datetime.now()),
|
|
|
+ "campaign_type": 2},
|
|
|
+ 'group_info': {'unit_name': account_id_to_name[self.account_id] + unit_name +
|
|
|
+ str(datetime.datetime.now()),
|
|
|
+ 'begin_time': str(datetime.date.today())},
|
|
|
+ 'creative_info': creative_info}
|