ai_strategy_request_func.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. import datetime
  2. import json
  3. import uuid
  4. import traceback
  5. from concurrent_log import ConcurrentTimedRotatingFileHandler
  6. import pandas as pd
  7. import pymysql
  8. import requests
  9. from utils.DataBaseConfig import *
  10. from utils.UrlConfig import *
  11. import logging
  12. log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', '%m/%d/%Y %I:%M:%S %p')
  13. log_handler = ConcurrentTimedRotatingFileHandler("logs/ai_strategy_request.log", when="midnight", backupCount=100)
  14. log_handler.setFormatter(log_formatter)
  15. logger = logging.getLogger('ai_strategy_request_logger')
  16. logger.addHandler(log_handler)
  17. logger.setLevel(logging.DEBUG)
  18. print('id of ai_strategy_request_logger %s' % id(logger))
  19. def ai_strategy_request_parse(data):
  20. """
  21. 发送创建组和创意的请求
  22. :param data:
  23. :return:
  24. """
  25. try:
  26. account_id_for_logger = None
  27. if data["operation_type"] == 1:
  28. inst = ParseAddCampaignOrAddGroupRequest(data)
  29. account_id_for_logger = inst.account_id
  30. logger.info("账户信息=%s, 当前进程=%s, 当前进程的主进程=%s" % (inst.account_id, os.getpid(), os.getppid()))
  31. # 1 获取客户策略信息
  32. inst.get_advertiser_strategy_info()
  33. # 2 写入智能策略信息
  34. inst.write_intelligence_strategy_table()
  35. # 3 判断 campaign_id 是否为空,为空则发送创建计划的请求
  36. if inst.campaign_id == "" or inst.campaign_id is None:
  37. if inst.add_campaign() == -1:
  38. return {'code': -2, 'message': '广告计划创建失败!'}
  39. # 4 unit_type "4-自定义" or "7-程序化创意2.0" ,调用对应的拼装参数函数
  40. if data['group_info'].get('unit_type', 4) == 4:
  41. inst.assemble_group_and_creative_params()
  42. if data['group_info'].get('unit_type', 4) == 7:
  43. inst.assemble_group_and_programme_creative_params()
  44. # 5 发送的请求信息更新到数据库表
  45. inst.update_intelligence_strategy_table(request_content=inst.res_data, message=None)
  46. # 6 发送创建组和创意的请求
  47. request = requests.post(create_group_and_creative_url,
  48. headers=headers,
  49. data=json.JSONEncoder().encode(inst.res_data))
  50. response_data = json.loads(request.text)
  51. # 7 接受的返回信息更新到数据库表
  52. inst.update_intelligence_strategy_table(message=response_data)
  53. # 8 写入日志信息
  54. logger.info("account_id = %s, 策略uuid = %s 的请求返回信息:%s" % (account_id_for_logger, inst.ai_strategy_uuid, response_data))
  55. return {'account_id': inst.account_id, 'code': 0, 'message': response_data}
  56. else:
  57. return {"account_id": account_id_for_logger, "code": -1, "message": "暂时不支持非新增的操作请求!"}
  58. except Exception:
  59. logger.error("account_id = %s, traceback is %s" % (account_id_for_logger, traceback.format_exc()))
  60. return {"account_id": account_id_for_logger, "message": traceback.format_exc(), "code": -2}
  61. # 该类解析的是 手动请求的新增广告计划或者新增广告组的数据
  62. class ParseAddCampaignOrAddGroupRequest(object):
  63. def __init__(self, request_data):
  64. self.ai_strategy_uuid = str(uuid.uuid4())
  65. self.request_data = request_data
  66. self.video = self.request_data['video']
  67. self.account_id = self.request_data['account_id']
  68. self.campaign_info = self.request_data['campaign_info']
  69. self.campaign_id = self.request_data['campaign_info'].get('campaign_id', None)
  70. self.group_info = self.request_data.get('group_info', None)
  71. self.creative_info = self.request_data.get('creative_info', None)
  72. self.operation_type = self.request_data['operation_type']
  73. self.advertiser_strategy_id = None
  74. self.advertiser_strategy = {}
  75. self.res_data = {}
  76. def get_advertiser_strategy_info(self):
  77. """
  78. 获取指定账户下客户的策略信息
  79. 为后续的写入库表,校验一致性做准备
  80. :return:
  81. """
  82. sql = """
  83. select *
  84. from ctop_ai_kuaishou_advertiser_strategy
  85. where account_id = %d
  86. limit 1
  87. """ % self.account_id
  88. advertiser_strategy_df = pd.read_sql(sql, engine)
  89. self.advertiser_strategy_id = int(advertiser_strategy_df['id'].values[0])
  90. self.advertiser_strategy = advertiser_strategy_df.T.to_dict()[0]
  91. def write_intelligence_strategy_table(self):
  92. """
  93. 请求信息写入 ctop_ai_kuaishou_intelligence_strategy 表中
  94. :return:
  95. """
  96. intelligence_strategy_dict = \
  97. {
  98. 'ai_strategy_uuid': self.ai_strategy_uuid,
  99. 'advertiser_strategy_id': self.advertiser_strategy_id,
  100. 'account_id': self.account_id,
  101. 'ai_strategy_receive_content': str(self.request_data),
  102. 'ai_strategy_remark': self.request_data['ai_strategy_remark'],
  103. 'create_time': datetime.datetime.now()
  104. }
  105. df = pd.DataFrame.from_dict(intelligence_strategy_dict, orient='index').T
  106. df.to_sql(name="ctop_ai_kuaishou_intelligence_strategy", con=engine, if_exists='append', index=False)
  107. def update_intelligence_strategy_table(self, request_content=None, message=None):
  108. """
  109. 更新 intelligence_strategy_table
  110. :return:
  111. """
  112. db_con = pymysql.connect(host=host,
  113. port=port,
  114. user=user,
  115. password=passwd,
  116. database=db,
  117. charset=charset)
  118. cursor = db_con.cursor()
  119. if request_content:
  120. cursor.execute("""UPDATE ctop_ai_kuaishou_intelligence_strategy
  121. SET ai_strategy_request_content= %s
  122. WHERE ai_strategy_uuid = %s""", (str(request_content), self.ai_strategy_uuid))
  123. if message:
  124. cursor.execute("""UPDATE ctop_ai_kuaishou_intelligence_strategy
  125. SET message = %s
  126. WHERE ai_strategy_uuid = %s""", (str(message), self.ai_strategy_uuid))
  127. db_con.commit()
  128. db_con.close()
  129. def add_campaign(self):
  130. """
  131. 新增广告计划, 创建成功之后写入计划层级操作表中
  132. :return:
  133. """
  134. create_campaign_req_data = \
  135. {'account_id': self.account_id,
  136. 'campaign_name': self.campaign_info['campaign_name'],
  137. 'type': self.advertiser_strategy['campaign_type']}
  138. request = requests.post(url=create_campaign_url,
  139. headers=headers,
  140. data=json.JSONEncoder().encode(create_campaign_req_data))
  141. res_data = json.loads(request.text)
  142. # res_data = {
  143. # "code": 0,
  144. # "data": {
  145. # "account_id": 23212,
  146. # "campaign_id": 30956133,
  147. # "campaign_create_time": "2021-01-13 13:50:16"
  148. # },
  149. # "message": "SUCCESS"}
  150. campaign_info_to_db = {
  151. 'campaign_uuid': str(uuid.uuid4()),
  152. 'account_id': self.account_id,
  153. 'ai_strategy_uuid': self.ai_strategy_uuid,
  154. 'campaign_name': self.campaign_info['campaign_name'],
  155. 'campaign_type': self.advertiser_strategy['campaign_type'],
  156. 'operation_type': self.operation_type,
  157. 'create_time': datetime.datetime.now()
  158. }
  159. res = 0
  160. logger.info("the res of create campaign is %s" % res_data)
  161. if res_data['code'] == 0:
  162. self.campaign_id = res_data['data'].get('campaign_id', None)
  163. campaign_info_to_db['campaign_id'] = self.campaign_id
  164. campaign_info_to_db['campaign_create_time'] = res_data['data'].get('campaign_create_time', None)
  165. campaign_info_to_db['status'] = res_data.get('code', None)
  166. campaign_info_to_db['message'] = res_data.get('message', None)
  167. logger.info("广告计划创建成功,campaign_id = %s, ai_strategy_uuid = %s" %
  168. (self.campaign_id, self.ai_strategy_uuid))
  169. else:
  170. campaign_info_to_db['message'] = res_data['message']
  171. campaign_info_to_db['status'] = res_data['code']
  172. logger.error("广告计划创建失败:%s, ai_strategy_uuid = %s" % (res_data['message'], self.ai_strategy_uuid))
  173. res = -1
  174. # 写入计划层级的操作表
  175. df = pd.DataFrame.from_dict(campaign_info_to_db, orient='index').T
  176. df.to_sql(name="ctop_ai_kuaishou_campaign_level_operation_record",
  177. con=engine,
  178. if_exists='append',
  179. index=False)
  180. return res
  181. def get_group_params(self):
  182. group_params = self.advertiser_strategy.copy()
  183. # 1 从客户策略表中,剔除掉不是组层级的参数(客户基本信息、计划层级信息、创意层级信息)
  184. drop_cols = ['id', 'account_id', 'status', 'campaign_type', 'campaign_name',
  185. 'creative_name', 'action_bar_text', 'description', 'short_slogan',
  186. 'sticker_title', 'overlay_type', 'expose_tag', 'new_expose_tag', 'site_id',
  187. 'click_track_url', 'impression_url', 'ad_photo_played_t3s_url', 'actionbar_click_url',
  188. 'creative_category', 'creative_tag', 'image_cnt',
  189. 'create_time', 'effective_time', 'expiry_time', 'timer_task_status',
  190. 'single_appid', 'app_id_array','general_track', 'open_program_create']
  191. for col in drop_cols:
  192. if col in group_params.keys():
  193. del group_params[col]
  194. # 2 从请求的信息中更新组层级信息, 如组的名称、测试定向、测试出价等, update客户策略信息
  195. if (self.group_info is not None) and (len(self.group_info) > 0):
  196. for key, value in self.group_info.items():
  197. if value is not None:
  198. group_params.update({key: value})
  199. # 3 smart_cover 和 asset_mining 需要将0/1 转化为 False/True
  200. group_params['smart_cover'] = True if group_params.get('smart_cover', 0) == 1 else False
  201. group_params['asset_mining'] = True if group_params.get('asset_mining', 0) == 1 else False
  202. # 4 拼装json的组参数
  203. group_params_to_request = group_params.copy()
  204. # 4-1 拼接发送请求json时, 以下字段需要转为 list 类型
  205. cols_to_list = ['app_store', 'scene_id', 'region', 'district_ids', 'ages_range', 'device_brand',
  206. 'device_price', 'business_interest', 'fans_star', 'interest_video', 'app_interest',
  207. 'app_ids', 'population', 'exclude_population', 'paid_audience', 'behavior_interest']
  208. for col in cols_to_list:
  209. group_params_to_request[col] = eval(group_params_to_request[col]) \
  210. if ((group_params_to_request[col] is not None) and (group_params_to_request[col] != '')) else None
  211. # 4-2 发送请求,需要将 group_name 改为 unit_name
  212. group_params_to_request['unit_name'] = group_params_to_request.pop('group_name')
  213. # 5 写入数据库的组参数
  214. group_params_to_db = group_params.copy()
  215. group_params_to_db['ai_strategy_uuid'] = self.ai_strategy_uuid
  216. group_params_to_db['account_id'] = self.account_id
  217. group_params_to_db['campaign_id'] = self.campaign_id
  218. group_params_to_db['operation_type'] = self.operation_type
  219. group_params_to_db['status'] = 1
  220. group_params_to_db['message'] = None
  221. return group_params_to_request, group_params_to_db
  222. def get_creative_params(self):
  223. # 1 从客户策略表中获取 创意层级基本信息
  224. creative_cols = ['creative_name', 'action_bar_text', 'description', 'short_slogan',
  225. 'sticker_title', 'overlay_type', 'expose_tag', 'new_expose_tag', 'site_id',
  226. 'click_track_url', 'impression_url', 'ad_photo_played_t3s_url', 'actionbar_click_url',
  227. 'creative_category', 'creative_tag']
  228. creative_params = {}
  229. for col in creative_cols:
  230. creative_params[col] = self.advertiser_strategy.get(col)
  231. # 2 从请求的信息中更新创意层级的信息,如广告语
  232. if (self.creative_info is not None) and (len(self.creative_info) > 0):
  233. for key, value in self.creative_info.items():
  234. if value is not None:
  235. creative_params.update({key: value})
  236. # 3 拼装json的 创意参数
  237. creative_params_to_request = creative_params.copy()
  238. # 3-1 拼接发送请求json时, 以下字段需要转为 list 类型
  239. cols_to_list = ['creative_tag']
  240. for col in cols_to_list:
  241. creative_params_to_request[col] = eval(creative_params_to_request[col]) \
  242. if ((creative_params_to_request[col] is not None) and (creative_params_to_request[col] != '')) else None
  243. # 4 写入数据库的创意参数
  244. creative_params_to_db = creative_params.copy()
  245. creative_params_to_db['ai_strategy_uuid'] = self.ai_strategy_uuid
  246. creative_params_to_db['account_id'] = self.account_id
  247. creative_params_to_db['campaign_id'] = self.campaign_id
  248. creative_params_to_db['operation_type'] = self.operation_type
  249. creative_params_to_db['status'] = 1
  250. creative_params_to_db['message'] = None
  251. return creative_params_to_request, creative_params_to_db
  252. def get_programme_creative_params(self):
  253. # 1 从客户策略表中获取 创意层级基本信息
  254. creative_cols = ['creative_name', 'action_bar_text', 'description', 'site_id',
  255. 'click_track_url', 'actionbar_click_url',
  256. 'creative_category', 'creative_tag']
  257. creative_params = {}
  258. for col in creative_cols:
  259. creative_params[col] = self.advertiser_strategy.get(col)
  260. # 2 从请求的信息中更新创意层级的信息,如广告语,创意名称等
  261. if (self.creative_info is not None) and (len(self.creative_info) > 0):
  262. for key, value in self.creative_info.items():
  263. if value is not None:
  264. creative_params.update({key: value})
  265. # 3 程序化创意部分字段发生改变,需要重命名
  266. # creative_name --> package_name(程序化创意名称)
  267. # action_bar_text --> action_bar(行动号召按钮)
  268. # description --> captions(作品广告语) string[]
  269. # click_track_url --> click_url(点击监测链接)
  270. creative_params['package_name'] = creative_params.pop('creative_name')
  271. creative_params['action_bar'] = creative_params.pop('action_bar_text')
  272. description = creative_params.pop('description')
  273. creative_params['captions'] = str([description])
  274. creative_params['click_url'] = creative_params.pop('click_track_url')
  275. # 4 拼装json的 创意参数
  276. creative_params_to_request = creative_params.copy()
  277. # 4-1 拼接发送请求json时, 以下字段需要转为 list 类型
  278. cols_to_list = ['creative_tag', 'captions']
  279. for col in cols_to_list:
  280. creative_params_to_request[col] = eval(creative_params_to_request[col]) \
  281. if ((creative_params_to_request[col] is not None) and (creative_params_to_request[col] != '')) else None
  282. # 5 写入数据库的创意参数
  283. creative_params_to_db = creative_params.copy()
  284. creative_params_to_db['ai_strategy_uuid'] = self.ai_strategy_uuid
  285. creative_params_to_db['account_id'] = self.account_id
  286. creative_params_to_db['campaign_id'] = self.campaign_id
  287. creative_params_to_db['operation_type'] = self.operation_type
  288. creative_params_to_db['status'] = 1
  289. creative_params_to_db['message'] = None
  290. return creative_params_to_request, creative_params_to_db
  291. def assemble_group_and_creative_params(self):
  292. """
  293. 拼接组和创意层级参数
  294. 写入数据库
  295. :return:
  296. """
  297. # 获取组和创意的基本参数
  298. group_params_to_request, group_params_to_db = self.get_group_params()
  299. creative_params_to_request, creative_params_to_db = self.get_creative_params()
  300. self.res_data['group_list'] = []
  301. group_cnt = 1
  302. for video in self.video:
  303. group_uuid = str(uuid.uuid4())
  304. group_name = group_params_to_db['group_name'] + '-' + str(group_cnt)
  305. # 写入数据表中组信息
  306. single_group_params_to_db = group_params_to_db.copy()
  307. single_group_params_to_db['group_uuid'] = group_uuid
  308. single_group_params_to_db['group_name'] = group_name
  309. single_group_params_to_db['create_time'] = datetime.datetime.now()
  310. df = pd.DataFrame.from_dict(single_group_params_to_db, orient='index').T
  311. df.to_sql(name="ctop_ai_kuaishou_unit_level_operation_record",
  312. con=engine,
  313. if_exists='append',
  314. index=False)
  315. # 拼装返回json的组信息
  316. single_group_params_to_request = group_params_to_request.copy()
  317. single_group_params_to_request['group_uuid'] = group_uuid
  318. single_group_params_to_request['unit_name'] = group_name
  319. single_group_params_to_request['creative_list'] = []
  320. group_cnt += 1
  321. # 拼装组下面创意的信息
  322. creative_cnt = 1
  323. for image_md5 in video['imageList'][: self.advertiser_strategy['image_cnt']]:
  324. creative_uuid = str(uuid.uuid4())
  325. creative_name = creative_params_to_db['creative_name'] + '_' + str(creative_cnt)
  326. single_creative_params_to_db = creative_params_to_db.copy()
  327. single_creative_params_to_db['creative_uuid'] = creative_uuid
  328. single_creative_params_to_db['creative_name'] = creative_name
  329. single_creative_params_to_db['photo_id'] = video['photo_id']
  330. single_creative_params_to_db['image_md5'] = image_md5
  331. single_creative_params_to_db['create_time'] = datetime.datetime.now()
  332. df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
  333. df.to_sql(name="ctop_ai_kuaishou_creative_level_operation_record",
  334. con=engine,
  335. if_exists='append',
  336. index=False)
  337. single_creative_params_to_request = creative_params_to_request.copy()
  338. single_creative_params_to_request['creative_uuid'] = creative_uuid
  339. single_creative_params_to_request['creative_name'] = creative_name
  340. single_creative_params_to_request['photo_id'] = video['photo_id']
  341. single_creative_params_to_request['image_md5'] = image_md5
  342. # 单个创意信息加入到组里面的 creative_list 中
  343. single_group_params_to_request['creative_list'].append(single_creative_params_to_request)
  344. creative_cnt += 1
  345. # 组和创意信息添加到最终返回数据 group_list 中
  346. self.res_data['group_list'].append(single_group_params_to_request)
  347. self.res_data['account_id'] = self.account_id
  348. self.res_data['campaign_id'] = self.campaign_id
  349. def assemble_group_and_programme_creative_params(self):
  350. """
  351. 拼接组和程序化创意的参数
  352. 写入数据库
  353. :return:
  354. """
  355. # 获取组和创意的基本参数
  356. group_params_to_request, group_params_to_db = self.get_group_params()
  357. creative_params_to_request, creative_params_to_db = self.get_programme_creative_params()
  358. # 每5个视频一组,来拼接组层级 和 程序化创意 层级的参数
  359. self.res_data['group_list'] = []
  360. cnt = 1
  361. is_smart_cover = group_params_to_request.get('smart_cover', 0)
  362. for i in range(0, len(self.video), 5):
  363. group_uuid = str(uuid.uuid4())
  364. group_name = group_params_to_db['group_name'] + '-' + str(cnt)
  365. # 写入数据表中组信息
  366. single_group_params_to_db = group_params_to_db.copy()
  367. single_group_params_to_db['group_uuid'] = group_uuid
  368. single_group_params_to_db['group_name'] = group_name
  369. single_group_params_to_db['create_time'] = datetime.datetime.now()
  370. df = pd.DataFrame.from_dict(single_group_params_to_db, orient='index').T
  371. df.to_sql(name="ctop_ai_kuaishou_unit_level_operation_record",
  372. con=engine,
  373. if_exists='append',
  374. index=False)
  375. # 拼装返回json的组信息
  376. single_group_params_to_request = group_params_to_request.copy()
  377. single_group_params_to_request['group_uuid'] = group_uuid
  378. single_group_params_to_request['unit_name'] = group_name
  379. single_group_params_to_request['creative_list'] = []
  380. single_group_params_to_request['programCreative'] = None
  381. # 拼装程序化创意的信息
  382. horizontal_photo_ids = []
  383. vertical_photo_ids = []
  384. cover_image_tokens = []
  385. if i+5 < len(self.video):
  386. for j in range(i, i+5, 1):
  387. if self.video[j]['material_type'] == 2:
  388. horizontal_photo_ids.append(self.video[j]['photo_id'])
  389. cover_image_tokens.append(self.video[j]['imageList'][0])
  390. if self.video[j]['material_type'] == 1:
  391. vertical_photo_ids.append(self.video[j]['photo_id'])
  392. cover_image_tokens.append(self.video[j]['imageList'][0])
  393. if len(cover_image_tokens) >= 5:
  394. cover_image_tokens = cover_image_tokens[:4]
  395. creative_uuid = str(uuid.uuid4())
  396. package_name = creative_params_to_db['package_name'] + '_' + str(cnt)
  397. single_creative_params_to_db = creative_params_to_db.copy()
  398. single_creative_params_to_db['creative_uuid'] = creative_uuid
  399. single_creative_params_to_db['package_name'] = package_name
  400. single_creative_params_to_db['horizontal_photo_ids'] = str(horizontal_photo_ids)
  401. single_creative_params_to_db['vertical_photo_ids'] = str(vertical_photo_ids)
  402. single_creative_params_to_db['cover_image_tokens'] = str(cover_image_tokens) if not is_smart_cover else None
  403. single_creative_params_to_db['create_time'] = datetime.datetime.now()
  404. df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
  405. df.to_sql(name="ctop_ai_kuaishou_program_creative_level_operation_record",
  406. con=engine,
  407. if_exists='append',
  408. index=False)
  409. single_creative_params_to_request = creative_params_to_request.copy()
  410. single_creative_params_to_request['creative_uuid'] = creative_uuid
  411. single_creative_params_to_request['package_name'] = package_name
  412. single_creative_params_to_request['horizontal_photo_ids'] = horizontal_photo_ids
  413. single_creative_params_to_request['vertical_photo_ids'] = vertical_photo_ids
  414. if not is_smart_cover:
  415. single_creative_params_to_request['image_md5s'] = cover_image_tokens
  416. else:
  417. # material_type=1 竖版
  418. # material_type=2 横版
  419. for j in range(i, len(self.video)):
  420. if self.video[j]['material_type'] == 2:
  421. horizontal_photo_ids.append(self.video[j]['photo_id'])
  422. cover_image_tokens.append(self.video[j]['imageList'][0])
  423. if self.video[j]['material_type'] == 1:
  424. vertical_photo_ids.append(self.video[j]['photo_id'])
  425. cover_image_tokens.append(self.video[j]['imageList'][0])
  426. if len(cover_image_tokens) >= 5:
  427. cover_image_tokens = cover_image_tokens[:4]
  428. creative_uuid = str(uuid.uuid4())
  429. package_name = creative_params_to_db['package_name'] + '_' + str(cnt)
  430. single_creative_params_to_db = creative_params_to_db.copy()
  431. single_creative_params_to_db['creative_uuid'] = creative_uuid
  432. single_creative_params_to_db['package_name'] = package_name
  433. single_creative_params_to_db['horizontal_photo_ids'] = str(horizontal_photo_ids)
  434. single_creative_params_to_db['vertical_photo_ids'] = str(vertical_photo_ids)
  435. single_creative_params_to_db['cover_image_tokens'] = str(cover_image_tokens) if not is_smart_cover else None
  436. single_creative_params_to_db['create_time'] = datetime.datetime.now()
  437. df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
  438. df.to_sql(name="ctop_ai_kuaishou_program_creative_level_operation_record",
  439. con=engine,
  440. if_exists='append',
  441. index=False)
  442. single_creative_params_to_request = creative_params_to_request.copy()
  443. single_creative_params_to_request['creative_uuid'] = creative_uuid
  444. single_creative_params_to_request['package_name'] = package_name
  445. single_creative_params_to_request['horizontal_photo_ids'] = horizontal_photo_ids
  446. single_creative_params_to_request['vertical_photo_ids'] = vertical_photo_ids
  447. if not is_smart_cover:
  448. single_creative_params_to_request['image_md5s'] = cover_image_tokens
  449. single_group_params_to_request['programCreative'] = single_creative_params_to_request
  450. cnt += 1
  451. self.res_data['group_list'].append(single_group_params_to_request)
  452. self.res_data['account_id'] = self.account_id
  453. self.res_data['campaign_id'] = self.campaign_id
  454. # TODO 修改操作
  455. class ParseModifyRequest(object):
  456. def __init__(self):
  457. pass
  458. # TODO 关停操作
  459. class ParseShutDownRequest(object):
  460. def __init__(self):
  461. pass