Explorar el Código

MOD:修复落地页图片问题

cxyu hace 3 años
padre
commit
9f51f51911

+ 1 - 1
web_module/tornado_api.py

@@ -86,7 +86,7 @@ class create_ad_plan(BaseHandler):
             return
         # 2.1存计划数据
         for _ in ad_plan_list:
-            ad_plan_name = _['title'].replace(' ', '')[:29]
+            ad_plan_name = _['title'].replace(' ', '').replace('.','').replace(',','')[:29]
             ad_plan_typesetting_info = {'user_id': user_id, 'name': ad_plan_name,
                                         'typesetting': json.dumps(_, ensure_ascii=False)}
             print('typesetting_info')

+ 5 - 1
web_module/user_action.py

@@ -46,7 +46,9 @@ def cookie_acion(db, log_ad, cookie_canuse, user_id):
 
 
 def carry_plan(user_id, ad_plan_list, log_ad, db, cookie_canuse):
-    # TODO:action_record涉及到的地方都需要改动
+    # TODO:与get_human_info的交互需要改动
+    # TODO:失败后 ,状态为:创建中  ----进行对应删除
+
     # 创建中的数据需要进行删除
 
     # TODO:
@@ -113,12 +115,14 @@ def carry_plan(user_id, ad_plan_list, log_ad, db, cookie_canuse):
             # 4.更新action_record相关计划信息
             sql_tools.action_record(res, sql_session, ad_plan_create_action, user_id, plan_name, action_record_table,
                                     service_name, wechat_name, task_name)
+            logging.info('创建计划任务结束')
             log_ad.refresh_driver()
             # 每次运行微信相关操作,对微信相关信息进行刷新
             get_human_info(user_id, log_ad, db, cookie_canuse)
     except Exception as e:
         log_ad.driver.save_screenshot(
             'user_id:{}_time_{}_plan_error.png'.format(user_id, datetime.now().strftime("%Y-%m-%d, %H:%M:%S")))
+        raise
         dingtalk.send_message('user_id:{} 计划执行出错,进行检查\n{}'.format(user_id, str(e)))
         logging.error(e)
     finally:

+ 2 - 2
wechat_action/create_ad_layout.py

@@ -552,7 +552,6 @@ class CreateAd:
             os.makedirs(self.img_dir)
         link_pra = re.split('\/', file_link)
         file_path = os.getcwd() + '/' + self.img_dir + '/' + link_pra[-1]
-
         rsp = requests.get(file_link)
         with open(file_path, 'wb') as f:
             f.write(rsp.content)
@@ -652,7 +651,7 @@ class CreateAd:
                 return True
 
     def check_sucess(self, layout_name):
-        # TODO:检查使用接口实现
+        # 检查使用接口实现----driver 版
 
         # 进入素材中心
         WebDriverWait(self.driver, 100).until(
@@ -707,6 +706,7 @@ class CreateAd:
                     self.get_into_create_page()
                     return self.create_layout(layout, err_num=err_num + 1)
         except Exception as e:
+            raise
             logging.error(e)
             # TODO:有空时讲 e 内容设置为原始内容
             if err_num > 3:

+ 9 - 8
wechat_action/create_ad_plan.py

@@ -37,14 +37,14 @@ class CreateAdPlan():
     def set_ad_cpm(self):
         # TODO:设置完之后,test函数中进行对应修改
         logging.info('开始设置cpm')
-        if self.task['cpm']['cpm_set'] == 2:
+        if self.task['cpm']['cpm_set'] == '2':
             self.driver.save_screenshot('cpm{}.png'.format(time.time()))
             self.driver.find_element_by_xpath(
                 '//*[@id="wxadcontainer"]/div[1]/div/div[2]/main/div/div[2]/div[1]/div/div[2]/div/div[1]/section[2]/form/div/div[1]/div[1]/button[2]/span').click()
             time.sleep(0.1)
             select_elements = self.driver.find_elements_by_xpath('//*[@class="adui-radio-base adui-radio-small"]')
             for _ in select_elements:
-                if '优先跑量' in _.text and self.task['cpm']['module'] == 2:
+                if '优先跑量' in _.text and self.task['cpm']['module'] == '2':
                     _.click()
                     time.sleep(0.1)
                 if '下单' in _.text:
@@ -106,7 +106,7 @@ class CreateAdPlan():
             lambda driver: self.driver.find_elements_by_xpath('//*[@class="adui-input-base"]'))
         input_elements = self.driver.find_elements_by_xpath('//*[@class="adui-input-base"]')
 
-        if self.task['date_set']['date_module'] == 2:
+        if self.task['date_set']['date_module'] == '2':
             select_elements = self.driver.find_elements_by_xpath('//*[@class="adui-radio-base adui-radio-small"]')
             for _ in select_elements:
                 if '长期投放' in _.text:
@@ -157,7 +157,7 @@ class CreateAdPlan():
             # self.driver.find_element_by_class_name('icon-3cAquX1RLZ').click()
             citys = self.driver.find_elements_by_class_name('checkbox-1pfRMRqv-R')
             for _ in citys:
-                _.click()
+                ActionChains(self.driver).move_to_element(_).click().perform()
 
     def set_ad_cost(self):
         # 投放计划创建
@@ -225,11 +225,11 @@ class CreateAdPlan():
 
     def set_ad_humam_gender(self):
         logging.info('设置性别')
-        if self.task['human_info_parameter']['gender'] == 0:
+        if self.task['human_info_parameter']['gender'] == '0':
             self.driver.find_element_by_xpath('//*[@id="gender_"]/span[2]').click()
-        if self.task['human_info_parameter']['gender'] == 1:
+        if self.task['human_info_parameter']['gender'] == '1':
             self.driver.find_element_by_xpath('//*[@id="gender_MALE"]/span[2]').click()
-        if self.task['human_info_parameter']['gender'] == 2:
+        if self.task['human_info_parameter']['gender'] == '2':
             self.driver.find_element_by_xpath('//*[@id="gender_FEMALE"]/span[2]').click()
 
     def set_ad_age(self):
@@ -353,6 +353,7 @@ class CreateAdPlan():
                     self.login_ad.select_ad_master(service_name=self, wechat_name=self.wechat_name)
                     return self.run(err_num=err_num + 1)
         except Exception as e:
+            raise
             time.sleep(5)
             self.driver.save_screenshot('liuyi{}.png'.format(time.time()))
             time.sleep(5)
@@ -362,5 +363,5 @@ class CreateAdPlan():
                 return {'sucess': False, 'result_info': str(e)}
             else:
                 self.login_ad.refresh_driver()
-                self.login_ad.select_ad_master(service_name=self, wechat_name=self.wechat_name)
+                self.login_ad.select_ad_master(service_name=self.service_name, wechat_name=self.wechat_name)
                 return self.run(err_num=err_num + 1)

+ 18 - 18
wechat_action/create_ad_plan_idea.py

@@ -35,24 +35,24 @@ class IdeaAction:
         select_elements = self.driver.find_elements_by_xpath('//*[@class="label-2ZOAbuO31o"]')
         # 点击跳转
         for _ in select_elements:
-            if _.text == '公众号详情页' and idea_dic['jump_type'] == 2:
+            if _.text == '公众号详情页' and idea_dic['jump_type'] == '2':
                 _.click()
         time.sleep(random.uniform(0.1, 0.2))
 
         # 按钮文案
         for _ in select_elements:
-            if _.text == '立即咨询' and idea_dic['button_type'] == 2:
+            if _.text == '立即咨询' and idea_dic['button_type'] == '2':
                 _.click()
-            if _.text == '立即申请' and idea_dic['button_type'] == 3:
+            if _.text == '立即申请' and idea_dic['button_type'] == '3':
                 _.click()
-            if _.text == '阅读小说' and idea_dic['button_type'] == 4:
+            if _.text == '阅读小说' and idea_dic['button_type'] == '4':
                 _.click()
         time.sleep(random.uniform(0.1, 0.2))
 
-        if idea_dic['jump_type'] == 1:
+        if idea_dic['jump_type'] == '1':
             # 点击按钮跳转
             for _ in select_elements:
-                if _.text == '一键关注' and idea_dic['jump_type_button_type'] == 2:
+                if _.text == '一键关注' and idea_dic['jump_type_button_type'] == '2':
                     _.click()
             time.sleep(random.uniform(0.1, 0.2))
 
@@ -88,12 +88,12 @@ class IdeaAction:
         select_elements = self.driver.find_elements_by_xpath('//*[@class="label-2ZOAbuO31o"]')
         input_elements = self.driver.find_elements_by_xpath('//*[@class="input-3MbKvywHL2"]')
         # 信息栏
-        if idea_dic['info_type'] == 1:
+        if idea_dic['info_type'] == '1':
             # 头像
             for _ in select_elements:
                 if _.text == '头像昵称型':
                     _.click()
-        if idea_dic['info_type'] == 2:
+        if idea_dic['info_type'] == '2':
             # 文案
             for _ in select_elements:
                 if _.text == '文案型':
@@ -138,11 +138,11 @@ class IdeaAction:
         self.push_promotion_page()
 
     def idea_gzh_bottom(self):
-        if self.task['idea']['idea_type'] == 1:
+        if self.task['idea']['idea_type'] == '1':
             self.idea_pic_gzh_botoom()
-        if self.task['idea']['idea_type'] == 2:
+        if self.task['idea']['idea_type'] == '2':
             self.idea_banner_pic_gzh_botoom()
-        if self.task['idea']['idea_type'] == 3:
+        if self.task['idea']['idea_type'] == '3':
             self.idea_banner_business_gzh_bottom()
 
     def idea_movie_gzh_movie(self):
@@ -174,12 +174,12 @@ class IdeaAction:
         select_elements = self.driver.find_elements_by_xpath('//*[@class="label-2ZOAbuO31o"]')
         input_elements = self.driver.find_elements_by_xpath('//*[@class="input-3MbKvywHL2"]')
         # 信息栏
-        if idea_dic['info_type'] == 1:
+        if idea_dic['info_type'] == '1':
             # 头像
             for _ in select_elements:
                 if _.text == '头像昵称型':
                     _.click()
-        if idea_dic['info_type'] == 2:
+        if idea_dic['info_type'] == '2':
             # 文案
             for _ in select_elements:
                 if _.text == '文案型':
@@ -210,11 +210,11 @@ class IdeaAction:
 
         # 标签展示
         for _ in select_elements:
-            if _.text == '不启用' and idea_dic['lable_type'] == 1:
+            if _.text == '不启用' and idea_dic['lable_type'] == '1':
                 _.click()
-            if _.text == '好友关注量标签' and idea_dic['lable_type'] == 2:
+            if _.text == '好友关注量标签' and idea_dic['lable_type'] == '2':
                 _.click()
-            if _.text == '转化目标量标签' and idea_dic['lable_type'] == 3:
+            if _.text == '转化目标量标签' and idea_dic['lable_type'] == '3':
                 _.click()
         time.sleep(random.uniform(0.1, 0.2))
 
@@ -273,10 +273,10 @@ class IdeaAction:
         time.sleep(random.uniform(0.1, 0.2))
 
         time.sleep(random.uniform(0.1, 0.5))
-        if self.task['idea']['data_show'] == 2:
+        if self.task['idea']['data_show'] == '2':
             self.driver.find_element_by_xpath(
                 '//*[@id="wxadcontainer"]/div[1]/div/div[2]/main/div/div[2]/div[2]/div/div[1]/div[1]/div[2]/form/div[5]/div[1]/div/span/span[1]').click()
-            if self.task['idea']['data_show-type'] == 2:
+            if self.task['idea']['data_show-type'] == '2':
                 time.sleep(random.uniform(0.1, 0.5))
                 WebDriverWait(self.driver, 100).until(lambda driver: self.driver.find_element_by_xpath(
                     '//*[@id="wxadcontainer"]/div[1]/div/div[2]/main/div/div[2]/div[2]/div/div[1]/div[1]/div[2]/form/div[5]/div[2]/div/div[1]/label/span[1]'))