Browse Source

MOD:添加 微信相关信息

cxyu 4 years ago
parent
commit
19786b83cd

+ 2 - 0
web_module/tornado_api.py

@@ -565,6 +565,8 @@ def make_app():
     return tornado.web.Application([
         ("/create_ad_task", create_ad_task),
         ("/create_ad_plan", create_ad_plan),
+        ("/get_ad_wechat_service_name", get_ad_wechat_service_name),
+        ("/get_ad_wechat_wechat_name", get_ad_wechat_wechat_name),
         # ("/create_ad_plan_local", create_ad_plan_local),
         # ("/create_ad_layout_local", create_ad_layout_local),
         ("/get_layout_local", get_ad_layout_local),

+ 64 - 54
wechat_action/create_ad_layout.py

@@ -65,11 +65,11 @@ class CreateAd:
 
     def set_head_assemb(self, info):
         def single_page_set():
-            #TODO:选择图片之后,还有一些其他选项
+            # TODO:选择图片之后,还有一些其他选项
             self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/div[1]/div/div[1]/div/div').click()
             time.sleep(random.uniform(0.1, 0.2))
 
-            file_name = re.split('\/', info_v)[-1]
+            file_name = re.split('\/', info['content']['url'])[-1]
             self.driver.find_element_by_class_name('upload-img-item-inner-2gsg7NjaZ8').click()
             WebDriverWait(self.driver, 10).until(
                 lambda x: len([_ for _ in self.driver.find_elements_by_class_name('title-29sncpKgTl') if
@@ -236,14 +236,14 @@ class CreateAd:
                 if _.is_enabled() and _.is_displayed():
                     _.click()
 
-        info_key = list(info.keys())[0]
-        info_v = info[info_key]
+        info_type = info['type']
+        info_v = None  # TODO: 暂时存在,之后修改好multi_page_set 和movie_set.就删除
 
-        if info_key == 'page':
+        if info['type'] == 'topImg':
             single_page_set()
-        if info_key == 'multi_page':
+        if info['type'] == 'multi_page':
             multi_page_set()
-        if info_key == 'movie':
+        if info['type'] == 'movie':
             movie_set()
 
         # 设置头部组件
@@ -336,7 +336,7 @@ class CreateAd:
         input_elements = self.driver.find_elements_by_xpath('//textarea[@class="adui-input-base"]')
         for _ in input_elements:
             if _.is_enabled() and _.is_displayed():
-                _.send_keys(config_info['content'])
+                _.send_keys(config_info['text'])
 
         # 设置颜色
         if config_info['color'] != '595959':
@@ -355,27 +355,29 @@ class CreateAd:
                     _.send_keys(config_info['color'])
 
         # 设置是否加粗
-        if config_info['is_bold']:
+        if config_info['fontWeight'] != 'normal':
+            # TODO:新格式  文本是否加粗,还不知道
             big_elements = self.driver.find_elements_by_class_name('adui-button-content')
             for _ in big_elements:
                 if _.text == '加粗' and _.is_displayed() and _.is_enabled():
                     _.click()
 
         # 设置文本位置
-        if config_info['loc'] != 'left':
+        if config_info['textAlign'] != 'left':
+            # TODO:新格式  文本位置设置,还不知道
             loc_buttons = self.driver.find_elements_by_xpath(
                 "//div[contains(@class, 'adui-button-group_banner')]//button")
             loc_buttons_can_use = []
             for _ in loc_buttons:
                 if _.is_enabled() and _.is_displayed():
                     loc_buttons_can_use.append(_)
-            if config_info['loc'] == 'middle':
+            if config_info['textAlign'] == 'center':
                 loc_buttons_can_use[1].click()
-            if config_info['loc'] == 'right':
+            if config_info['textAlign'] == 'right':
                 loc_buttons_can_use[2].click()
 
         # 设置文本大小
-        if config_info['str_num'] != 15:
+        if config_info['fontSize'] != 15:
             str_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-selection-search']")
             str_buttons_can_use = []
             for _ in str_buttons:
@@ -390,10 +392,10 @@ class CreateAd:
                 if _.is_displayed() and _.is_enabled():
                     str_num_can_use.append(_)
             str_num_map = {14: 0, 16: 1, 18: 2, 20: 3, 24: 4, 36: 5}
-            str_num_can_use[str_num_map[config_info['str_num']]].click()
+            str_num_can_use[str_num_map[config_info['fontSize']]].click()
 
         # 设置文本边距
-        if config_info['str_distance'][0] != 22 or config_info['str_distance'][1] != 22:
+        if config_info['marginTop'] != 22 or config_info['marginBottom'] != 22:
             distance_buttons = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
             distance_buttons_can_use = []
             for _ in distance_buttons:
@@ -402,11 +404,11 @@ class CreateAd:
             distance_buttons_can_use[0].click()
             for i in range(4):
                 distance_buttons_can_use[0].send_keys(Keys.BACKSPACE)
-            distance_buttons_can_use[0].send_keys(config_info['str_distance'][0])
+            distance_buttons_can_use[0].send_keys(config_info['marginTop'])
             distance_buttons_can_use[1].click()
             for i in range(4):
                 distance_buttons_can_use[1].send_keys(Keys.BACKSPACE)
-            distance_buttons_can_use[1].send_keys(config_info['str_distance'][1])
+            distance_buttons_can_use[1].send_keys(config_info['str_dimarginBottomstance'])
 
     def set_follow_button(self, button_type):
         # 设置关注按钮
@@ -514,10 +516,10 @@ class CreateAd:
                 _.clear()
                 for i in range(10):
                     _.send_keys(Keys.BACKSPACE)
-                _.send_keys(config_info['content'])
+                _.send_keys(config_info['text'])
 
         # 文本是否加粗
-        if config_info['is_bold']:
+        if config_info['fontWeight'] != 'normal':
             big_elements = self.driver.find_elements_by_xpath('//span[@class="adui-button-content"]')
             for _ in big_elements:
                 if _.text == '加粗' and _.is_displayed() and _.is_enabled():
@@ -532,13 +534,13 @@ class CreateAd:
                 input_elements_can_use.append(_)
 
         input_elements_can_use[0].click()
-        input_elements_can_use[0].send_keys(config_info['color1'])
+        input_elements_can_use[0].send_keys(config_info['textColor'])
         time.sleep(random.uniform(0.1, 0.5))
         input_elements_can_use[1].click()
-        input_elements_can_use[1].send_keys(config_info['color2'])
+        input_elements_can_use[1].send_keys(config_info['borderColor'])
         time.sleep(random.uniform(0.1, 0.5))
         input_elements_can_use[2].click()
-        input_elements_can_use[2].send_keys(config_info['color3'])
+        input_elements_can_use[2].send_keys(config_info['backColor'])
         time.sleep(random.uniform(0.1, 0.5))
 
         # 间隙设置
@@ -550,11 +552,11 @@ class CreateAd:
         size_buttons_can_use[0].click()
         for i in range(4):
             size_buttons_can_use[0].send_keys(Keys.BACKSPACE)
-        size_buttons_can_use[0].send_keys(config_info['str_distance'][0])
+        size_buttons_can_use[0].send_keys(config_info['marginTop'])
         size_buttons_can_use[1].click()
         for i in range(4):
             size_buttons_can_use[1].send_keys(Keys.BACKSPACE)
-        size_buttons_can_use[1].send_keys(config_info['str_distance'][1])
+        size_buttons_can_use[1].send_keys(config_info['marginBottom'])
 
     def set_text_button(self):
         # 设置图文按钮
@@ -650,6 +652,16 @@ class CreateAd:
         self.driver.find_element_by_xpath('//*[@id="wxadcontainer"]/div[1]/div[2]/div[4]/input').send_keys(file_path)
 
     def send_file_alone(self, layout):
+        def get_url(v_info):
+            if 'url' in v_info.keys():
+                file_set.add(v_info['url'])
+            for v in v_info.values():
+                if isinstance(v, dict):
+                    get_url(v)
+                if isinstance(v, list):
+                    for _ in v:
+                        if isinstance(_, dict):
+                            get_url(_)
         # 上传文件,单线程
         # 上传文件,文件上传与整体流程切割开
         WebDriverWait(self.driver, 10).until(
@@ -662,15 +674,19 @@ class CreateAd:
         time.sleep(random.uniform(1, 2))
         self.driver.switch_to.window(self.driver.window_handles[-1])
         file_set = set()
-        for v in layout.values():
-            if isinstance(v, dict):
-                if 'multi_page' in v.keys() or 'page' in v.keys() or 'movie' in v.keys():
-                    v_name = list(v.keys())[0]
-                    if isinstance(v[v_name], list):
-                        for _ in v[v_name]:
-                            file_set.add(_)
-                    else:
-                        file_set.add(v[v_name])
+        # TODO:之后还有multi_page 和 movie
+        # for v in layout.values():
+        #     if isinstance(v, dict):
+        #         if 'multi_page' in v.keys() or 'page' in v.keys() or 'movie' in v.keys():
+        #             v_name = list(v.keys())[0]
+        #             if isinstance(v[v_name], list):
+        #                 for _ in v[v_name]:
+        #                     file_set.add(_)
+        #             else:
+        #                 file_set.add(v[v_name])
+
+
+        get_url(layout)
         for _ in file_set:
             self.send_file(_)
             err_num = 0
@@ -689,9 +705,7 @@ class CreateAd:
         self.driver.execute_script('window.close();')
         self.driver.switch_to.window(self.driver.window_handles[-1])
 
-    def set_share_content(self, share_info):
-        title_content = share_info['share_info']['title']
-        des_content = share_info['share_info']['des']
+    def set_share_content(self, title_content, des_content):
         self.driver.find_element_by_xpath('//*[@id="wxadcontainer"]/div[1]/div/section/header/div[2]/button[2]').click()
         WebDriverWait(self.driver, 50).until(lambda driver: driver.find_element_by_xpath(
             '//*[@id="wxadcontainer"]/div[1]/div/div/div/div[1]/section/section/div[2]/div[1]/div/div/input'))
@@ -736,26 +750,22 @@ class CreateAd:
         #
         try:
             self.send_file_alone(layout)
-            self.set_advertisement_sign(layout_name=layout[-4]['layout_name'])
-            self.set_head_assemb(layout[str(-1)])
-            if -2 in layout.keys():
-                self.set_background_color(layout['bc_color']['color'])
-
-            for _ in range(max([int(x) for x in layout.keys()]) + 1):
-                info = layout[str(_)]
-                info_key = list(info.keys())[0]
-                info_v = info[info_key]
-                if info_key == 'page':
-                    self.set_page(info_v)
-                if info_key == 'content':
-                    self.set_content(info_v)
-                if info_key == 'follow_button':
-                    self.set_follow_button_(info_v)
-
-            self.set_share_content(layout[str(-3)])
+            self.set_advertisement_sign(layout_name=layout['layoutName'])
+            self.set_head_assemb(layout['topContent'])
+            self.set_background_color(layout['pageBackColor'])
+
+            for _ in layout['content']:
+                if _['type'] == 'img':
+                    self.set_page(page_link=_['content']['url'])
+                if _['type'] == 'txt':
+                    self.set_content(_['content'])
+                if _['type'] == 'followAcc':
+                    self.set_follow_button_(_['content'])
+
+            self.set_share_content(title_content=layout['shareTittle'], des_content=layout['shareDesc'])
 
             self.remove_all_file()
-            if self.check_sucess(layout_name=layout[-4]['layout_name']):
+            if self.check_sucess(layout_name=layout['layoutName']):
                 return {'sucess': True, 'result_info': ''}
             else:
                 if err_num > 3:

+ 7 - 7
wechat_action/login_ad.py

@@ -16,6 +16,7 @@ import requests
 import json
 import logging
 
+
 class LogIn:
     # TODO:整体运行使用逻辑,需要修改几次
     def __init__(self):
@@ -34,11 +35,11 @@ class LogIn:
         # prefs = {"profile.managed_default_content_settings.images": 2, 'permissions.default.stylesheet': 2}
         # options.add_experimental_option("prefs", prefs)
 
-        driver = webdriver.Remote(
-            # command_executor='http://192.168.1.101:4444/wd/hub',
-            command_executor='http://118.31.53.105:4555/wd/hub',
-            options=options)
-        # driver = webdriver.Chrome(options=options)
+        # driver = webdriver.Remote(
+        #     # command_executor='http://192.168.1.101:4444/wd/hub',
+        #     command_executor='http://118.31.53.105:4555/wd/hub',
+        #     options=options)
+        driver = webdriver.Chrome(options=options)
         driver.maximize_window()
         return driver
 
@@ -61,7 +62,6 @@ class LogIn:
         WebDriverWait(self.driver, 6 * 60).until(lambda driver: self.driver.find_elements_by_link_text('广告投放'))
         logging.info('登录成功')
 
-
     def select_ad_master(self, service_name, wechat_name):
         logging.info('开始切换服务商')
         time.sleep(5)
@@ -174,4 +174,4 @@ class LogIn:
                 err_num = err_num + 1
                 if err_num > 3:
                     break
-        logging.info('刷新chrome 结束')
+        logging.info('刷新chrome 结束')

+ 1 - 1
wechat_action/sql_tools.py

@@ -319,7 +319,7 @@ def get_wechat_info_service_name(sql_session, user_id):
     '''.format(user_id)
     cursor = sql_session.execute(sql)
     lines = cursor.fetchall()
-    result_list = [line for line in lines]
+    result_list = [line[0] for line in lines]
     return result_list