|
@@ -3,10 +3,11 @@ from utils.UrlConfig import *
|
|
import json
|
|
import json
|
|
import logging
|
|
import logging
|
|
import traceback
|
|
import traceback
|
|
|
|
+import random
|
|
import tornado.web
|
|
import tornado.web
|
|
from concurrent_log import ConcurrentTimedRotatingFileHandler
|
|
from concurrent_log import ConcurrentTimedRotatingFileHandler
|
|
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_top_video_info, get_campaign_and_group_name_rule,get_app_detail, get_request_data
|
|
from utils.ConstantConfig import *
|
|
from utils.ConstantConfig import *
|
|
from ai_strategy_request_func import ai_strategy_request_parse
|
|
from ai_strategy_request_func import ai_strategy_request_parse
|
|
from utils.DataBaseConfig import *
|
|
from utils.DataBaseConfig import *
|
|
@@ -41,7 +42,10 @@ class AiHistoricalMissingMaterial(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:
|
|
- for app_id in 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:
|
|
# 1、获取该 app_id 的应该详情
|
|
# 1、获取该 app_id 的应该详情
|
|
app_id_info = get_app_detail(account_id=account_id,
|
|
app_id_info = get_app_detail(account_id=account_id,
|
|
url=get_app_detail_url,
|
|
url=get_app_detail_url,
|
|
@@ -68,9 +72,9 @@ class AiHistoricalMissingMaterial(tornado.web.RequestHandler):
|
|
campaign_id = getattr(row, 'campaign_id')
|
|
campaign_id = getattr(row, 'campaign_id')
|
|
break
|
|
break
|
|
|
|
|
|
- # 3、获取通用视频5个
|
|
|
|
|
|
+ # 3、获取通用视频1个
|
|
general_video_info = get_missing_video_info(account_id=account_id,
|
|
general_video_info = get_missing_video_info(account_id=account_id,
|
|
- cnt=5,
|
|
|
|
|
|
+ cnt=1,
|
|
url=get_missing_video_url,
|
|
url=get_missing_video_url,
|
|
start_time=missing_video_start_time,
|
|
start_time=missing_video_start_time,
|
|
end_time=missing_video_end_time,
|
|
end_time=missing_video_end_time,
|
|
@@ -79,9 +83,9 @@ class AiHistoricalMissingMaterial(tornado.web.RequestHandler):
|
|
logger.info('account_id=%s, app_id=%s, the res of general_video_info is %s' %
|
|
logger.info('account_id=%s, app_id=%s, the res of general_video_info is %s' %
|
|
(account_id, app_id, general_video_info['message']))
|
|
(account_id, app_id, general_video_info['message']))
|
|
|
|
|
|
- # 4、获取app_id对应的视频50个
|
|
|
|
|
|
+ # 4、获取app_id对应的视频1个
|
|
special_video_info = get_missing_video_info(account_id=account_id,
|
|
special_video_info = get_missing_video_info(account_id=account_id,
|
|
- cnt=50,
|
|
|
|
|
|
+ cnt=1,
|
|
url=get_missing_video_url,
|
|
url=get_missing_video_url,
|
|
start_time=missing_video_start_time,
|
|
start_time=missing_video_start_time,
|
|
end_time=missing_video_end_time,
|
|
end_time=missing_video_end_time,
|
|
@@ -112,11 +116,10 @@ class AiHistoricalMissingMaterial(tornado.web.RequestHandler):
|
|
click_track_url=track_url)
|
|
click_track_url=track_url)
|
|
request = ai_strategy_request_parse(request_data)
|
|
request = ai_strategy_request_parse(request_data)
|
|
logger.info("account_id=%s, app_id=%s, ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
logger.info("account_id=%s, app_id=%s, ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
- else:
|
|
|
|
- logger.info("account_id=%s, app_id=%s, 没有获取到视频,不发送ai策略请求!" % (account_id, app_id))
|
|
|
|
-
|
|
|
|
- # TODO 返回信息如何组织内容
|
|
|
|
- self.write(json.dumps({"account_id=%s, 多应用的补充遗漏素材请求已走完!" % account_id}))
|
|
|
|
|
|
+ app_id_cnt += 1
|
|
|
|
+ if app_id_cnt >= 50:
|
|
|
|
+ break
|
|
|
|
+ self.write(json.dumps({"message": "account_id=%s, 多应用的补充遗漏素材请求已走完!" % account_id}))
|
|
self.flush()
|
|
self.flush()
|
|
else:
|
|
else:
|
|
video_info = get_missing_video_info(account_id,
|
|
video_info = get_missing_video_info(account_id,
|
|
@@ -242,7 +245,7 @@ class AiAutoCreative(tornado.web.RequestHandler):
|
|
else:
|
|
else:
|
|
logger.info("account_id=%s, app_id=%s, 没有获取到视频,不发送ai策略请求!" % (account_id, app_id))
|
|
logger.info("account_id=%s, app_id=%s, 没有获取到视频,不发送ai策略请求!" % (account_id, app_id))
|
|
|
|
|
|
- self.write(json.dumps({"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')
|
|
@@ -310,7 +313,10 @@ class AiHighQualityMaterial(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:
|
|
- for app_id in 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:
|
|
# 1、获取该 app_id 的应该详情
|
|
# 1、获取该 app_id 的应该详情
|
|
app_id_info = get_app_detail(account_id=account_id,
|
|
app_id_info = get_app_detail(account_id=account_id,
|
|
url=get_app_detail_url,
|
|
url=get_app_detail_url,
|
|
@@ -337,25 +343,27 @@ class AiHighQualityMaterial(tornado.web.RequestHandler):
|
|
campaign_id = getattr(row, 'campaign_id')
|
|
campaign_id = getattr(row, 'campaign_id')
|
|
break
|
|
break
|
|
|
|
|
|
- # 3、获取通用视频
|
|
|
|
|
|
+ # 3、获取1个通用视频
|
|
general_video_info = get_top_video_info(account_id=account_id,
|
|
general_video_info = get_top_video_info(account_id=account_id,
|
|
url=get_high_quality_video_url,
|
|
url=get_high_quality_video_url,
|
|
start_time=(datetime.datetime.now() +
|
|
start_time=(datetime.datetime.now() +
|
|
datetime.timedelta(days=-high_quality_video_days)).
|
|
datetime.timedelta(days=-high_quality_video_days)).
|
|
- strftime("%Y-%m-%d"),
|
|
|
|
- end_time=str(datetime.date.today()),
|
|
|
|
|
|
+ strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ cnt=1,
|
|
app_version='all')
|
|
app_version='all')
|
|
if general_video_info['code'] != 0:
|
|
if general_video_info['code'] != 0:
|
|
logger.info('account_id=%s, app_id=%s, the res of general_video_info is %s' %
|
|
logger.info('account_id=%s, app_id=%s, the res of general_video_info is %s' %
|
|
(account_id, app_id, general_video_info['message']))
|
|
(account_id, app_id, general_video_info['message']))
|
|
|
|
|
|
- # 4、获取app_id对应的视频
|
|
|
|
|
|
+ # 4、获取app_id对应的1个视频
|
|
special_video_info = get_top_video_info(account_id=account_id,
|
|
special_video_info = get_top_video_info(account_id=account_id,
|
|
url=get_high_quality_video_url,
|
|
url=get_high_quality_video_url,
|
|
start_time=(datetime.datetime.now() +
|
|
start_time=(datetime.datetime.now() +
|
|
datetime.timedelta(days=-high_quality_video_days)).
|
|
datetime.timedelta(days=-high_quality_video_days)).
|
|
- strftime("%Y-%m-%d"),
|
|
|
|
- end_time=str(datetime.date.today()),
|
|
|
|
|
|
+ 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)
|
|
app_version=app_version)
|
|
if special_video_info['code'] != 0:
|
|
if special_video_info['code'] != 0:
|
|
logger.info('account_id=%s, app_id=%s, the res of special_video_info is %s' %
|
|
logger.info('account_id=%s, app_id=%s, the res of special_video_info is %s' %
|
|
@@ -383,16 +391,17 @@ class AiHighQualityMaterial(tornado.web.RequestHandler):
|
|
click_track_url=track_url)
|
|
click_track_url=track_url)
|
|
request = ai_strategy_request_parse(request_data)
|
|
request = ai_strategy_request_parse(request_data)
|
|
logger.info("account_id=%s, app_id=%s, ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
logger.info("account_id=%s, app_id=%s, ai策略的返回信息:%s" % (account_id, app_id, request))
|
|
- else:
|
|
|
|
- logger.info("account_id=%s, app_id=%s, 没有获取到视频,不发送ai策略请求!" % (account_id, app_id))
|
|
|
|
-
|
|
|
|
- self.write(json.dumps({"account_id=%s, 多应用的高质量素材复建请求已走完!" % account_id}))
|
|
|
|
|
|
+ app_id_cnt += 1
|
|
|
|
+ if app_id_cnt >= 50:
|
|
|
|
+ break
|
|
|
|
+ self.write(json.dumps({"message": "account_id=%s, 多应用的高质量素材复建请求已走完!" % account_id}))
|
|
self.flush()
|
|
self.flush()
|
|
else:
|
|
else:
|
|
video_info = get_top_video_info(account_id, high_quality_video_cnt,
|
|
video_info = get_top_video_info(account_id, high_quality_video_cnt,
|
|
(datetime.datetime.now() + datetime.timedelta(
|
|
(datetime.datetime.now() + datetime.timedelta(
|
|
- days=-high_quality_video_days)).strftime("%Y-%m-%d"),
|
|
|
|
- str(datetime.date.today()), get_high_quality_video_url)
|
|
|
|
|
|
+ days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ get_high_quality_video_url)
|
|
if video_info['code'] != 0:
|
|
if video_info['code'] != 0:
|
|
logger.info("the res of video is %s" % video_info['message'])
|
|
logger.info("the res of video is %s" % video_info['message'])
|
|
logger.info("没有获取到视频,不发送ai策略请求!")
|
|
logger.info("没有获取到视频,不发送ai策略请求!")
|
|
@@ -422,12 +431,9 @@ class AiHighQualityMaterial(tornado.web.RequestHandler):
|
|
self.flush()
|
|
self.flush()
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
|
|
class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
|
|
"""
|
|
"""
|
|
- 每天22:00 调用该任务,检查当天创意是否创建达到上限,否则使用历史高质量素材填满 -- 测试通过 在AD后台创建成功,检查AD信息和数据库表 没有问题
|
|
|
|
|
|
+ 每天22:00 调用该任务,检查当天创意是否创建达到上限,否则使用历史高质量素材填满
|
|
"""
|
|
"""
|
|
def post(self):
|
|
def post(self):
|
|
data = self.request.body
|
|
data = self.request.body
|
|
@@ -439,24 +445,15 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
|
|
|
|
|
|
logger.info("账户信息=%s, 当前进程=%s, 当前进程的主进程=%s, raw data from request is %s" %
|
|
logger.info("账户信息=%s, 当前进程=%s, 当前进程的主进程=%s, raw data from request is %s" %
|
|
(account_id, os.getpid(), os.getppid(), data))
|
|
(account_id, os.getpid(), os.getppid(), data))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
try:
|
|
try:
|
|
start_time = (datetime.date.today()).strftime('%Y-%m-%d %H:%M:%S')
|
|
start_time = (datetime.date.today()).strftime('%Y-%m-%d %H:%M:%S')
|
|
end_time = (datetime.datetime.now()).strftime('%Y-%m-%d %H:%M:%S')
|
|
end_time = (datetime.datetime.now()).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
+ now = datetime.datetime.now()
|
|
|
|
|
|
- # 1-1 获取当天计划中包含“高质量素材”计划的,计划id
|
|
|
|
- sql = """
|
|
|
|
- select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
- where account_id = %s
|
|
|
|
- and put_create_time >= '%s'
|
|
|
|
- and put_create_time <= '%s'
|
|
|
|
- """ % (account_id, start_time, end_time)
|
|
|
|
- df = pd.read_sql(sql, engine)
|
|
|
|
- for row in df.itertuples():
|
|
|
|
- if '高质量素材' in getattr(row, 'campaign_name'):
|
|
|
|
- campaign_id = getattr(row, 'campaign_id')
|
|
|
|
- break
|
|
|
|
-
|
|
|
|
- # 2-1 从客户策略表中获取该账户下 每个素材搭配的封面个数, 来计算需要补充的素材个数
|
|
|
|
|
|
+ # 1-1 从客户策略表中获取该账户下 每个素材搭配的封面个数, 来计算需要补充的素材个数
|
|
sql = """
|
|
sql = """
|
|
select image_cnt from ctop_ai_kuaishou_advertiser_strategy
|
|
select image_cnt from ctop_ai_kuaishou_advertiser_strategy
|
|
where account_id = %s
|
|
where account_id = %s
|
|
@@ -466,7 +463,7 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
|
|
df = pd.read_sql(sql, engine)
|
|
df = pd.read_sql(sql, engine)
|
|
image_cnt = int(df['image_cnt'].values[0])
|
|
image_cnt = int(df['image_cnt'].values[0])
|
|
|
|
|
|
- # 3-1 从 ctop_kuaishou_creative 获取当天该账户到此刻 已经创建的创意个数
|
|
|
|
|
|
+ # 2-1 从 ctop_kuaishou_creative 获取当天该账户到此刻 已经创建的创意个数
|
|
video_cnt = 0
|
|
video_cnt = 0
|
|
sql = """
|
|
sql = """
|
|
select count(1) creative_cnt from ctop_kuaishou_creative
|
|
select count(1) creative_cnt from ctop_kuaishou_creative
|
|
@@ -482,42 +479,125 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
|
|
else:
|
|
else:
|
|
video_cnt = (2000 - creative_cnt) // image_cnt
|
|
video_cnt = (2000 - creative_cnt) // image_cnt
|
|
|
|
|
|
- # 4-1 获取视频信息
|
|
|
|
|
|
+ # 3-1 获取视频信息
|
|
if video_cnt == 0:
|
|
if video_cnt == 0:
|
|
logger.info("创意已经建满,不需要补充素材!")
|
|
logger.info("创意已经建满,不需要补充素材!")
|
|
self.write(json.dumps("message: 创意已经建满,不需要补充素材!"))
|
|
self.write(json.dumps("message: 创意已经建满,不需要补充素材!"))
|
|
self.flush()
|
|
self.flush()
|
|
else:
|
|
else:
|
|
logger.info("需要补充的视频数量:%s" % video_cnt)
|
|
logger.info("需要补充的视频数量:%s" % video_cnt)
|
|
- now = datetime.datetime.now()
|
|
|
|
- video_info = get_top_video_info(account_id,
|
|
|
|
- video_cnt,
|
|
|
|
- (now + datetime.timedelta(days=-2*high_quality_video_days)).strftime("%Y-%m-%d"),
|
|
|
|
- (now + datetime.timedelta(days=-high_quality_video_days)).strftime("%Y-%m-%d"),
|
|
|
|
- get_high_quality_video_url)
|
|
|
|
- if video_info['code'] != 0:
|
|
|
|
- logger.info("the res of video is %s" % video_info['message'])
|
|
|
|
- logger.info("没有获取到视频,不发送ai策略请求!")
|
|
|
|
- self.write(json.dumps({"message": "没有获取到视频,不发送ai策略请求!"}))
|
|
|
|
- self.flush()
|
|
|
|
- else:
|
|
|
|
- campaign_name, group_name = get_campaign_and_group_name_rule(account_id)
|
|
|
|
- if (campaign_name is None) or (group_name is None):
|
|
|
|
- logger.info("没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!")
|
|
|
|
- self.write(json.dumps({"message": "没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"}))
|
|
|
|
- self.flush()
|
|
|
|
- else:
|
|
|
|
|
|
+
|
|
|
|
+ sql = """select account_id, single_appid, app_id_array, general_track from ctop_ai_kuaishou_advertiser_strategy
|
|
|
|
+ where account_id=%s and status=1 order by create_time desc limit 1
|
|
|
|
+ """ % account_id
|
|
|
|
+ df = pd.read_sql(sql, engine)
|
|
|
|
+ if df['general_track'].values[0] == 0:
|
|
|
|
+ needed_app_id_cnt = video_cnt
|
|
|
|
+ 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:
|
|
|
|
+ # 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:
|
|
|
|
+ logger.info('account_id=%s, app_id=%s,the res of get_app_detail is %s' %
|
|
|
|
+ (account_id, app_id, app_id_info['message']))
|
|
|
|
+ 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')
|
|
|
|
+
|
|
|
|
+ start_time = (datetime.date.today()).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
+ end_time = (datetime.datetime.now()).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
+ sql = """ select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
+ where account_id = %s
|
|
|
|
+ and put_create_time >= '%s'
|
|
|
|
+ and put_create_time <= '%s'
|
|
|
|
+ """ % (account_id, start_time, end_time)
|
|
|
|
+ campaign_df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in campaign_df.itertuples():
|
|
|
|
+ if ('高质量素材' in getattr(row, 'campaign_name')) and (
|
|
|
|
+ app_version in 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:
|
|
|
|
+ logger.info('account_id=%s, app_id=%s, the res of special_video_info is %s' %
|
|
|
|
+ (account_id, app_id, special_video_info['message']))
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ # 6、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
+ # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
+ # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
request_data = get_request_data(account_id=account_id,
|
|
request_data = get_request_data(account_id=account_id,
|
|
campaign_id=campaign_id,
|
|
campaign_id=campaign_id,
|
|
- video_info=video_info['data'],
|
|
|
|
- campaign_name=campaign_name,
|
|
|
|
- group_name=group_name,
|
|
|
|
|
|
+ video_info=special_video_info['data'],
|
|
|
|
+ campaign_name=app_version + '-优选广告位-' + '高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-自定义-' + '高质量素材',
|
|
ai_strategy_remark="用高质量素材补满创意",
|
|
ai_strategy_remark="用高质量素材补满创意",
|
|
- name_replace="高质量素材")
|
|
|
|
|
|
+ unit_type=4,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
request = ai_strategy_request_parse(request_data)
|
|
request = ai_strategy_request_parse(request_data)
|
|
- logger.info("ai策略的返回信息:%s" % request)
|
|
|
|
- self.write(json.dumps(request))
|
|
|
|
|
|
+ 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()
|
|
|
|
+ else:
|
|
|
|
+ # 1-1 获取当天计划中包含“高质量素材”计划的,计划id
|
|
|
|
+ sql = """
|
|
|
|
+ select campaign_id, campaign_name from ctop_kuaishou_campaign
|
|
|
|
+ where account_id = %s
|
|
|
|
+ and put_create_time >= '%s'
|
|
|
|
+ and put_create_time <= '%s'
|
|
|
|
+ """ % (account_id, start_time, end_time)
|
|
|
|
+ df = pd.read_sql(sql, engine)
|
|
|
|
+ for row in df.itertuples():
|
|
|
|
+ if '高质量素材' in getattr(row, 'campaign_name'):
|
|
|
|
+ campaign_id = getattr(row, 'campaign_id')
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ video_info = get_top_video_info(account_id,
|
|
|
|
+ video_cnt,
|
|
|
|
+ (now + datetime.timedelta(days=-2*high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ (now + datetime.timedelta(days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ get_high_quality_video_url)
|
|
|
|
+ if video_info['code'] != 0:
|
|
|
|
+ logger.info("the res of video is %s" % video_info['message'])
|
|
|
|
+ logger.info("没有获取到视频,不发送ai策略请求!")
|
|
|
|
+ self.write(json.dumps({"message": "没有获取到视频,不发送ai策略请求!"}))
|
|
self.flush()
|
|
self.flush()
|
|
|
|
+ else:
|
|
|
|
+ campaign_name, group_name = get_campaign_and_group_name_rule(account_id)
|
|
|
|
+ if (campaign_name is None) or (group_name is None):
|
|
|
|
+ logger.info("没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!")
|
|
|
|
+ self.write(json.dumps({"message": "没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"}))
|
|
|
|
+ self.flush()
|
|
|
|
+ else:
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=video_info['data'],
|
|
|
|
+ campaign_name=campaign_name,
|
|
|
|
+ group_name=group_name,
|
|
|
|
+ ai_strategy_remark="用高质量素材补满创意",
|
|
|
|
+ name_replace="高质量素材")
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("ai策略的返回信息:%s" % request)
|
|
|
|
+ self.write(json.dumps(request))
|
|
|
|
+ self.flush()
|
|
except Exception:
|
|
except Exception:
|
|
logger.error(traceback.format_exc())
|
|
logger.error(traceback.format_exc())
|
|
self.write(json.dumps(traceback.format_exc()))
|
|
self.write(json.dumps(traceback.format_exc()))
|
|
@@ -555,36 +635,92 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
|
|
campaign_id = data.get('campaign_id')
|
|
campaign_id = data.get('campaign_id')
|
|
logger.info("账户信息=%s, 当前进程=%s, 当前进程的主进程=%s, raw data from request is %s" %
|
|
logger.info("账户信息=%s, 当前进程=%s, 当前进程的主进程=%s, raw data from request is %s" %
|
|
(account_id, os.getpid(), os.getppid(), data))
|
|
(account_id, os.getpid(), os.getppid(), data))
|
|
-
|
|
|
|
try:
|
|
try:
|
|
- video_info = get_top_video_info(account_id, programme_high_quality_video_cnt,
|
|
|
|
- (datetime.datetime.now() + datetime.timedelta(
|
|
|
|
- days=-high_quality_video_days)).strftime("%Y-%m-%d"),
|
|
|
|
- str(datetime.date.today()), get_high_quality_video_url)
|
|
|
|
- if video_info['code'] != 0:
|
|
|
|
- logger.info("the res of video is %s" % video_info['message'])
|
|
|
|
- logger.info("没有获取到视频,不发送ai策略请求!")
|
|
|
|
- self.write(json.dumps({"message": "没有获取到视频,不发送ai策略请求!"}))
|
|
|
|
- self.flush()
|
|
|
|
- else:
|
|
|
|
- campaign_name, group_name = get_campaign_and_group_name_rule(account_id)
|
|
|
|
- if (campaign_name is None) or (group_name is None):
|
|
|
|
- logger.info("没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!")
|
|
|
|
- self.write(json.dumps({"message": "没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"}))
|
|
|
|
- self.flush()
|
|
|
|
- else:
|
|
|
|
|
|
+ sql = """select account_id, single_appid, app_id_array, general_track from ctop_ai_kuaishou_advertiser_strategy
|
|
|
|
+ where account_id=%s and status=1 order by create_time desc limit 1
|
|
|
|
+ """ % account_id
|
|
|
|
+ df = pd.read_sql(sql, engine)
|
|
|
|
+ if df['general_track'].values[0] == 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:
|
|
|
|
+ # 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:
|
|
|
|
+ logger.info('account_id=%s, app_id=%s, the res of get_app_detail is %s' %
|
|
|
|
+ (account_id, app_id, app_id_info['message']))
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ 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:
|
|
|
|
+ logger.info('account_id=%s, app_id=%s, the res of special_video_info is %s' %
|
|
|
|
+ (account_id, app_id, special_video_info['message']))
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ # 3、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
+ # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
+ # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
request_data = get_request_data(account_id=account_id,
|
|
request_data = get_request_data(account_id=account_id,
|
|
campaign_id=campaign_id,
|
|
campaign_id=campaign_id,
|
|
- video_info=video_info['data'],
|
|
|
|
- campaign_name=campaign_name,
|
|
|
|
- group_name=group_name,
|
|
|
|
|
|
+ video_info=special_video_info['data'],
|
|
|
|
+ campaign_name=app_version + '-优选广告位-' + '程序化高质量素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-程序化-' + '高质量素材',
|
|
ai_strategy_remark="程序化高质量素材",
|
|
ai_strategy_remark="程序化高质量素材",
|
|
- name_replace="程序化高质量素材",
|
|
|
|
- unit_type=7)
|
|
|
|
|
|
+ unit_type=7,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
request = ai_strategy_request_parse(request_data)
|
|
request = ai_strategy_request_parse(request_data)
|
|
- logger.info("ai策略的返回信息:%s" % request)
|
|
|
|
- self.write(json.dumps(request))
|
|
|
|
|
|
+ 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
|
|
|
|
+
|
|
|
|
+ self.write(json.dumps({"message": "account_id=%s, 多应用的高质量素材程序化创意的请求已走完!" % account_id}))
|
|
|
|
+ self.flush()
|
|
|
|
+ else:
|
|
|
|
+ video_info = get_top_video_info(account_id, programme_high_quality_video_cnt,
|
|
|
|
+ (datetime.datetime.now() + datetime.timedelta(
|
|
|
|
+ days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ get_high_quality_video_url)
|
|
|
|
+ if video_info['code'] != 0:
|
|
|
|
+ logger.info("the res of video is %s" % video_info['message'])
|
|
|
|
+ logger.info("没有获取到视频,不发送ai策略请求!")
|
|
|
|
+ self.write(json.dumps({"message": "没有获取到视频,不发送ai策略请求!"}))
|
|
self.flush()
|
|
self.flush()
|
|
|
|
+ else:
|
|
|
|
+ campaign_name, group_name = get_campaign_and_group_name_rule(account_id)
|
|
|
|
+ if (campaign_name is None) or (group_name is None):
|
|
|
|
+ logger.info("没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!")
|
|
|
|
+ self.write(json.dumps({"message": "没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"}))
|
|
|
|
+ self.flush()
|
|
|
|
+ else:
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=video_info['data'],
|
|
|
|
+ campaign_name=campaign_name,
|
|
|
|
+ group_name=group_name,
|
|
|
|
+ ai_strategy_remark="程序化高质量素材",
|
|
|
|
+ name_replace="程序化高质量素材",
|
|
|
|
+ unit_type=7)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("ai策略的返回信息:%s" % request)
|
|
|
|
+ self.write(json.dumps(request))
|
|
|
|
+ self.flush()
|
|
except Exception:
|
|
except Exception:
|
|
logger.error(traceback.format_exc())
|
|
logger.error(traceback.format_exc())
|
|
self.write(json.dumps(traceback.format_exc()))
|
|
self.write(json.dumps(traceback.format_exc()))
|
|
@@ -593,7 +729,7 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
|
|
|
|
|
|
class AiProgramCreativeNewMaterial(tornado.web.RequestHandler):
|
|
class AiProgramCreativeNewMaterial(tornado.web.RequestHandler):
|
|
"""
|
|
"""
|
|
- 使用近期创意数关联小于10(当天创意关联数小于10的,150个素材)的素材创建程序化创意
|
|
|
|
|
|
+ 使用2天内 创意数关联小于10(当天创意关联数小于10的,150个素材)的素材创建程序化创意
|
|
计划名称--新素材程序化
|
|
计划名称--新素材程序化
|
|
timeTask: 每天上午10点执行 --(0 0 10 * * ?)
|
|
timeTask: 每天上午10点执行 --(0 0 10 * * ?)
|
|
"""
|
|
"""
|
|
@@ -606,64 +742,96 @@ class AiProgramCreativeNewMaterial(tornado.web.RequestHandler):
|
|
campaign_id = data.get('campaign_id')
|
|
campaign_id = data.get('campaign_id')
|
|
logger.info("账户信息=%s, 当前进程=%s, 当前进程的主进程=%s, raw data from request is %s" %
|
|
logger.info("账户信息=%s, 当前进程=%s, 当前进程的主进程=%s, raw data from request is %s" %
|
|
(account_id, os.getpid(), os.getppid(), data))
|
|
(account_id, os.getpid(), os.getppid(), data))
|
|
-
|
|
|
|
try:
|
|
try:
|
|
- video_info = get_history_video_info(account_id=account_id,
|
|
|
|
- url=get_history_video_url,
|
|
|
|
- start_time=(datetime.datetime.now() + datetime.timedelta(days=-2)).
|
|
|
|
- strftime("%Y-%m-%d"),
|
|
|
|
- end_time=str(datetime.date.today()),
|
|
|
|
- video_cnt=programme_new_video_cnt,
|
|
|
|
- related_creative_max_cnt=related_creative_max_cnt)
|
|
|
|
- if video_info['code'] != 0:
|
|
|
|
- logger.info("the res of video is %s" % video_info['message'])
|
|
|
|
- logger.info("没有获取到视频,不发送ai策略请求!")
|
|
|
|
- self.write(json.dumps({"message": "没有获取到视频,不发送ai策略请求!"}))
|
|
|
|
- self.flush()
|
|
|
|
- else:
|
|
|
|
- campaign_name, group_name = get_campaign_and_group_name_rule(account_id)
|
|
|
|
- if (campaign_name is None) or (group_name is None):
|
|
|
|
- logger.info("没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!")
|
|
|
|
- self.write(json.dumps({"message": "没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"}))
|
|
|
|
- self.flush()
|
|
|
|
- else:
|
|
|
|
|
|
+ sql = """select account_id, single_appid, app_id_array, general_track from ctop_ai_kuaishou_advertiser_strategy
|
|
|
|
+ where account_id=%s and status=1 order by create_time desc limit 1
|
|
|
|
+ """ % account_id
|
|
|
|
+ df = pd.read_sql(sql, engine)
|
|
|
|
+ if df['general_track'].values[0] == 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:
|
|
|
|
+ # 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:
|
|
|
|
+ logger.info('account_id=%s, app_id=%s, the res of get_app_detail is %s' %
|
|
|
|
+ (account_id, app_id, app_id_info['message']))
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ 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=-200)).
|
|
|
|
+ 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:
|
|
|
|
+ logger.info('account_id=%s, app_id=%s, the res of special_video_info is %s' %
|
|
|
|
+ (account_id, app_id, special_video_info['message']))
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ # 3、拼装request_data,调用ai_strategy_request_parse方法
|
|
|
|
+ # 广告计划名称:渠道包 - 游戏名称 - 版位 - 日期
|
|
|
|
+ # 广告组名称:渠道包 - 游戏名称 - 优选 - 不限(定向)-自定义 / 程序化 - 日期
|
|
request_data = get_request_data(account_id=account_id,
|
|
request_data = get_request_data(account_id=account_id,
|
|
campaign_id=campaign_id,
|
|
campaign_id=campaign_id,
|
|
- video_info=video_info['data'],
|
|
|
|
- campaign_name=campaign_name,
|
|
|
|
- group_name=group_name,
|
|
|
|
|
|
+ video_info=special_video_info['data'],
|
|
|
|
+ campaign_name=app_version + '-优选广告位-' + '程序化上新素材',
|
|
|
|
+ group_name=app_version + '-优选广告位-不限-程序化-' + '上新素材',
|
|
ai_strategy_remark="程序化上新素材",
|
|
ai_strategy_remark="程序化上新素材",
|
|
- name_replace="程序化上新素材",
|
|
|
|
- unit_type=7)
|
|
|
|
|
|
+ unit_type=7,
|
|
|
|
+ app_id=app_id,
|
|
|
|
+ click_track_url=track_url)
|
|
request = ai_strategy_request_parse(request_data)
|
|
request = ai_strategy_request_parse(request_data)
|
|
- logger.info("ai策略的返回信息:%s" % request)
|
|
|
|
- self.write(json.dumps(request))
|
|
|
|
|
|
+ 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
|
|
|
|
+
|
|
|
|
+ self.write(json.dumps({"message": "account_id=%s, 多应用的上新素材程序化创意的请求已走完!" % account_id}))
|
|
|
|
+ self.flush()
|
|
|
|
+ else:
|
|
|
|
+ video_info = get_history_video_info(account_id=account_id,
|
|
|
|
+ url=get_history_video_url,
|
|
|
|
+ start_time=(datetime.datetime.now() + datetime.timedelta(days=-2)).
|
|
|
|
+ strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ end_time=datetime.date.today().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
+ video_cnt=programme_new_video_cnt,
|
|
|
|
+ related_creative_max_cnt=related_creative_max_cnt)
|
|
|
|
+ if video_info['code'] != 0:
|
|
|
|
+ logger.info("the res of video is %s" % video_info['message'])
|
|
|
|
+ logger.info("没有获取到视频,不发送ai策略请求!")
|
|
|
|
+ self.write(json.dumps({"message": "没有获取到视频,不发送ai策略请求!"}))
|
|
self.flush()
|
|
self.flush()
|
|
|
|
+ else:
|
|
|
|
+ campaign_name, group_name = get_campaign_and_group_name_rule(account_id)
|
|
|
|
+ if (campaign_name is None) or (group_name is None):
|
|
|
|
+ logger.info("没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!")
|
|
|
|
+ self.write(json.dumps({"message": "没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"}))
|
|
|
|
+ self.flush()
|
|
|
|
+ else:
|
|
|
|
+ request_data = get_request_data(account_id=account_id,
|
|
|
|
+ campaign_id=campaign_id,
|
|
|
|
+ video_info=video_info['data'],
|
|
|
|
+ campaign_name=campaign_name,
|
|
|
|
+ group_name=group_name,
|
|
|
|
+ ai_strategy_remark="程序化上新素材",
|
|
|
|
+ name_replace="程序化上新素材",
|
|
|
|
+ unit_type=7)
|
|
|
|
+ request = ai_strategy_request_parse(request_data)
|
|
|
|
+ logger.info("ai策略的返回信息:%s" % request)
|
|
|
|
+ self.write(json.dumps(request))
|
|
|
|
+ self.flush()
|
|
except Exception:
|
|
except Exception:
|
|
logger.error(traceback.format_exc())
|
|
logger.error(traceback.format_exc())
|
|
self.write(json.dumps(traceback.format_exc()))
|
|
self.write(json.dumps(traceback.format_exc()))
|
|
- self.flush()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def get_request_data(account_id, campaign_id, video_info, campaign_name, group_name,
|
|
|
|
- ai_strategy_remark, name_replace='',
|
|
|
|
- unit_type=4, click_track_url=None, app_id=None):
|
|
|
|
- res = {
|
|
|
|
- "video": video_info,
|
|
|
|
- "operation_type": 1,
|
|
|
|
- "account_id": account_id,
|
|
|
|
- "ai_strategy_remark": ai_strategy_remark,
|
|
|
|
- "campaign_info":
|
|
|
|
- {"campaign_id": campaign_id,
|
|
|
|
- "campaign_name": (campaign_name.replace('自定义', name_replace) + str(datetime.datetime.now()))
|
|
|
|
- if not name_replace else (campaign_name + str(datetime.datetime.now()))},
|
|
|
|
- 'group_info':
|
|
|
|
- {'group_name': (group_name.replace('自定义', name_replace) + str(datetime.datetime.now()))
|
|
|
|
- if not name_replace else (group_name + str(datetime.datetime.now())),
|
|
|
|
- 'begin_time': str(datetime.date.today()),
|
|
|
|
- 'unit_type': unit_type,
|
|
|
|
- 'app_id': app_id},
|
|
|
|
- 'creative_info': {'is_sticky': 0,
|
|
|
|
- 'click_track_url': click_track_url}
|
|
|
|
- }
|
|
|
|
- return res
|
|
|
|
|
|
+ self.flush()
|