|  | @@ -26,6 +26,7 @@ def ai_strategy_request_parse(data):
 | 
	
		
			
				|  |  |      :param data:
 | 
	
		
			
				|  |  |      :return:
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  | +    print(data)
 | 
	
		
			
				|  |  |      if data["operation_type"] == 1:
 | 
	
		
			
				|  |  |          inst = ParseAddCampaignOrAddGroupRequest(data)
 | 
	
		
			
				|  |  |          # 1 获取客户策略信息
 | 
	
	
		
			
				|  | @@ -69,7 +70,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |      def __init__(self, request_data):
 | 
	
		
			
				|  |  |          self.ai_strategy_uuid = str(uuid.uuid4())
 | 
	
		
			
				|  |  |          self.request_data = request_data
 | 
	
		
			
				|  |  | -        self.video = self.request_data['video']
 | 
	
		
			
				|  |  | +        self.video = self.request_data['video']['data']
 | 
	
		
			
				|  |  |          self.account_id = self.request_data['account_id']
 | 
	
		
			
				|  |  |          self.campaign_info = self.request_data['campaign_info']
 | 
	
		
			
				|  |  |          self.campaign_id = self.request_data['campaign_info'].get('campaign_id', None)
 | 
	
	
		
			
				|  | @@ -96,7 +97,7 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |          """ % self.account_id
 | 
	
		
			
				|  |  |          advertiser_strategy_df = pd.read_sql(sql, engine)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        self.advertiser_strategy_id = advertiser_strategy_df['id'].values[0]
 | 
	
		
			
				|  |  | +        self.advertiser_strategy_id = int(advertiser_strategy_df['id'].values[0])
 | 
	
		
			
				|  |  |          self.advertiser_strategy = advertiser_strategy_df.T.to_dict()[0]
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def write_intelligence_strategy_table(self):
 | 
	
	
		
			
				|  | @@ -114,7 +115,10 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |                  'create_time': datetime.datetime.now()
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          df = pd.DataFrame.from_dict(intelligence_strategy_dict, orient='index').T
 | 
	
		
			
				|  |  | +        print(df.dtypes)
 | 
	
		
			
				|  |  | +        print("$$$$$$$$$$$$$")
 | 
	
		
			
				|  |  |          df.to_sql(name="ctop_ai_kuaishou_intelligence_strategy", con=engine, if_exists='append', index=False)
 | 
	
		
			
				|  |  | +        print("^^^^^^^^^^^^^^^^^^^^")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def update_intelligence_strategy_table(self, request_content=None, message=None):
 | 
	
		
			
				|  |  |          """
 | 
	
	
		
			
				|  | @@ -170,8 +174,6 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |              'campaign_name': self.campaign_info['campaign_name'],
 | 
	
		
			
				|  |  |              'campaign_type': self.advertiser_strategy['campaign_type'],
 | 
	
		
			
				|  |  |              'operation_type': self.operation_type,
 | 
	
		
			
				|  |  | -            'status': 1,
 | 
	
		
			
				|  |  | -            'message': None,
 | 
	
		
			
				|  |  |              'create_time': datetime.datetime.now()
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          res = 0
 | 
	
	
		
			
				|  | @@ -179,22 +181,26 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |              self.campaign_id = res_data['data']['campaign_id']
 | 
	
		
			
				|  |  |              campaign_info_to_db['campaign_id'] = self.campaign_id
 | 
	
		
			
				|  |  |              campaign_info_to_db['campaign_create_time'] = res_data['data']['campaign_create_time']
 | 
	
		
			
				|  |  | +            campaign_info_to_db['status'] = res_data['code']
 | 
	
		
			
				|  |  |              campaign_info_to_db['message'] = res_data['message']
 | 
	
		
			
				|  |  |              logger.info("广告计划创建成功,campaign_id = %s,  ai_strategy_uuid = %s" %
 | 
	
		
			
				|  |  |                          (self.campaign_id, self.ai_strategy_uuid))
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          else:
 | 
	
		
			
				|  |  |              campaign_info_to_db['message'] = res_data['message']
 | 
	
		
			
				|  |  | -            campaign_info_to_db['status'] = -1
 | 
	
		
			
				|  |  | +            campaign_info_to_db['status'] = res_data['code']
 | 
	
		
			
				|  |  |              logger.error("广告计划创建失败:%s,  ai_strategy_uuid = %s" % (res_data['message'], self.ai_strategy_uuid))
 | 
	
		
			
				|  |  |              res = -1
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          # 写入计划层级的操作表
 | 
	
		
			
				|  |  | +        print("%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 | 
	
		
			
				|  |  |          df = pd.DataFrame.from_dict(campaign_info_to_db, orient='index').T
 | 
	
		
			
				|  |  | +        print(df.dtypes)
 | 
	
		
			
				|  |  |          df.to_sql(name="ctop_ai_kuaishou_campaign_level_operation_record",
 | 
	
		
			
				|  |  |                    con=engine,
 | 
	
		
			
				|  |  |                    if_exists='append',
 | 
	
		
			
				|  |  |                    index=False)
 | 
	
		
			
				|  |  | +        print("^^^^^^^^^^^^^^^^^^^^^^^^")
 | 
	
		
			
				|  |  |          return res
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def get_group_params(self):
 | 
	
	
		
			
				|  | @@ -205,9 +211,10 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |                       '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', 'timer_task_status']
 | 
	
		
			
				|  |  |          for col in drop_cols:
 | 
	
		
			
				|  |  | -            del group_params[col]
 | 
	
		
			
				|  |  | +            if col in group_params.keys():
 | 
	
		
			
				|  |  | +                del group_params[col]
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          # 2 从请求的信息中更新组层级信息, 如组的名称、测试定向、测试出价等, update客户策略信息
 | 
	
		
			
				|  |  |          if (self.group_info is not None) and (len(self.group_info) > 0):
 | 
	
	
		
			
				|  | @@ -288,17 +295,18 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |          # 3 程序化创意部分字段发生改变,需要重命名
 | 
	
		
			
				|  |  |          #   creative_name  --> package_name(程序化创意名称)
 | 
	
		
			
				|  |  |          #   action_bar_text --> action_bar(行动号召按钮)
 | 
	
		
			
				|  |  | -        #   description --> captions(作品广告语)
 | 
	
		
			
				|  |  | +        #   description --> captions(作品广告语) string[]
 | 
	
		
			
				|  |  |          #   click_track_url --> click_url(点击监测链接)
 | 
	
		
			
				|  |  |          creative_params['package_name'] = creative_params.pop('creative_name')
 | 
	
		
			
				|  |  |          creative_params['action_bar'] = creative_params.pop('action_bar_text')
 | 
	
		
			
				|  |  | -        creative_params['captions'] = creative_params.pop('description')
 | 
	
		
			
				|  |  | +        description = creative_params.pop('description')
 | 
	
		
			
				|  |  | +        creative_params['captions'] = str([description])
 | 
	
		
			
				|  |  |          creative_params['click_url'] = creative_params.pop('click_track_url')
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          # 4 拼装json的 创意参数
 | 
	
		
			
				|  |  |          creative_params_to_request = creative_params.copy()
 | 
	
		
			
				|  |  |          # 4-1 拼接发送请求json时, 以下字段需要转为 list 类型
 | 
	
		
			
				|  |  | -        cols_to_list = ['creative_tag']
 | 
	
		
			
				|  |  | +        cols_to_list = ['creative_tag', 'captions']
 | 
	
		
			
				|  |  |          for col in cols_to_list:
 | 
	
		
			
				|  |  |              creative_params_to_request[col] = eval(creative_params_to_request[col]) \
 | 
	
		
			
				|  |  |                  if creative_params_to_request[col] is not None else None
 | 
	
	
		
			
				|  | @@ -422,10 +430,10 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |              cover_image_tokens = []
 | 
	
		
			
				|  |  |              if i+5 < len(self.video):
 | 
	
		
			
				|  |  |                  for j in range(i, i+5, 1):
 | 
	
		
			
				|  |  | -                    if self.video[j]['material_type'] == 1:
 | 
	
		
			
				|  |  | +                    if self.video[j]['material_type'] == 2:
 | 
	
		
			
				|  |  |                          horizontal_photo_ids.append(self.video[j]['photo_id'])
 | 
	
		
			
				|  |  |                          cover_image_tokens.append(self.video[j]['imageList'][0])
 | 
	
		
			
				|  |  | -                    if self.video[j]['material_type'] == 2:
 | 
	
		
			
				|  |  | +                    if self.video[j]['material_type'] == 1:
 | 
	
		
			
				|  |  |                          vertical_photo_ids.append(self.video[j]['photo_id'])
 | 
	
		
			
				|  |  |                          cover_image_tokens.append(self.video[j]['imageList'][0])
 | 
	
		
			
				|  |  |                  if len(cover_image_tokens) >= 5:
 | 
	
	
		
			
				|  | @@ -436,9 +444,9 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |                  single_creative_params_to_db = creative_params_to_db.copy()
 | 
	
		
			
				|  |  |                  single_creative_params_to_db['creative_uuid'] = creative_uuid
 | 
	
		
			
				|  |  |                  single_creative_params_to_db['package_name'] = package_name
 | 
	
		
			
				|  |  | -                single_creative_params_to_db['horizontal_photo_ids'] = horizontal_photo_ids
 | 
	
		
			
				|  |  | -                single_creative_params_to_db['vertical_photo_ids'] = vertical_photo_ids
 | 
	
		
			
				|  |  | -                single_creative_params_to_db['cover_image_tokens'] = cover_image_tokens
 | 
	
		
			
				|  |  | +                single_creative_params_to_db['horizontal_photo_ids'] = str(horizontal_photo_ids)
 | 
	
		
			
				|  |  | +                single_creative_params_to_db['vertical_photo_ids'] = str(vertical_photo_ids)
 | 
	
		
			
				|  |  | +                single_creative_params_to_db['cover_image_tokens'] = str(cover_image_tokens)
 | 
	
		
			
				|  |  |                  single_creative_params_to_db['create_time'] = datetime.datetime.now()
 | 
	
		
			
				|  |  |                  df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
 | 
	
		
			
				|  |  |                  df.to_sql(name="ctop_ai_kuaishou_program_creative_level_operation_record",
 | 
	
	
		
			
				|  | @@ -453,11 +461,13 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |                  single_creative_params_to_request['vertical_photo_ids'] = vertical_photo_ids
 | 
	
		
			
				|  |  |                  single_creative_params_to_request['image_md5s'] = cover_image_tokens
 | 
	
		
			
				|  |  |              else:
 | 
	
		
			
				|  |  | +                # material_type=1 竖版
 | 
	
		
			
				|  |  | +                # material_type=2 横版
 | 
	
		
			
				|  |  |                  for j in range(i, len(self.video)):
 | 
	
		
			
				|  |  | -                    if self.video[j]['material_type'] == 1:
 | 
	
		
			
				|  |  | +                    if self.video[j]['material_type'] == 2:
 | 
	
		
			
				|  |  |                          horizontal_photo_ids.append(self.video[j]['photo_id'])
 | 
	
		
			
				|  |  |                          cover_image_tokens.append(self.video[j]['imageList'][0])
 | 
	
		
			
				|  |  | -                    if self.video[j]['material_type'] == 2:
 | 
	
		
			
				|  |  | +                    if self.video[j]['material_type'] == 1:
 | 
	
		
			
				|  |  |                          vertical_photo_ids.append(self.video[j]['photo_id'])
 | 
	
		
			
				|  |  |                          cover_image_tokens.append(self.video[j]['imageList'][0])
 | 
	
		
			
				|  |  |                  if len(cover_image_tokens) >= 5:
 | 
	
	
		
			
				|  | @@ -468,9 +478,9 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |                  single_creative_params_to_db = creative_params_to_db.copy()
 | 
	
		
			
				|  |  |                  single_creative_params_to_db['creative_uuid'] = creative_uuid
 | 
	
		
			
				|  |  |                  single_creative_params_to_db['package_name'] = package_name
 | 
	
		
			
				|  |  | -                single_creative_params_to_db['horizontal_photo_ids'] = horizontal_photo_ids
 | 
	
		
			
				|  |  | -                single_creative_params_to_db['vertical_photo_ids'] = vertical_photo_ids
 | 
	
		
			
				|  |  | -                single_creative_params_to_db['cover_image_tokens'] = cover_image_tokens
 | 
	
		
			
				|  |  | +                single_creative_params_to_db['horizontal_photo_ids'] = str(horizontal_photo_ids)
 | 
	
		
			
				|  |  | +                single_creative_params_to_db['vertical_photo_ids'] = str(vertical_photo_ids)
 | 
	
		
			
				|  |  | +                single_creative_params_to_db['cover_image_tokens'] = str(cover_image_tokens)
 | 
	
		
			
				|  |  |                  single_creative_params_to_db['create_time'] = datetime.datetime.now()
 | 
	
		
			
				|  |  |                  df = pd.DataFrame.from_dict(single_creative_params_to_db, orient='index').T
 | 
	
		
			
				|  |  |                  df.to_sql(name="ctop_ai_kuaishou_program_creative_level_operation_record",
 | 
	
	
		
			
				|  | @@ -488,7 +498,9 @@ class ParseAddCampaignOrAddGroupRequest(object):
 | 
	
		
			
				|  |  |              single_group_params_to_request['programCreative'] = single_creative_params_to_request
 | 
	
		
			
				|  |  |              cnt += 1
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        self.res_data['group_list'].append(single_group_params_to_request)
 | 
	
		
			
				|  |  | +            self.res_data['group_list'].append(single_group_params_to_request)
 | 
	
		
			
				|  |  | +        self.res_data['account_id'] = self.account_id
 | 
	
		
			
				|  |  | +        self.res_data['campaign_id'] = self.campaign_id
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # TODO 修改操作
 |