|
@@ -15,9 +15,9 @@ from logging import handlers
|
|
|
|
|
|
|
|
|
class CreateAd:
|
|
|
- def __init__(self):
|
|
|
+ def __init__(self, service_name, wechat_name):
|
|
|
# TODO:创建完页面需要关闭所有页面并回到一开始的页面
|
|
|
- self.driver = LogIn().get_driver_loged()
|
|
|
+ self.driver = LogIn(service_name, wechat_name).get_driver_loged()
|
|
|
self.get_into_create_page()
|
|
|
self.send_file_limit_num = 8
|
|
|
|
|
@@ -41,6 +41,15 @@ class CreateAd:
|
|
|
# 创建编排
|
|
|
pass
|
|
|
|
|
|
+ def set_advertisement_sign(self):
|
|
|
+ # 设置广告标记
|
|
|
+ now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
+ self.driver.find_element_by_xpath('//*[@class="icon-edQB0KK2VG"]').click()
|
|
|
+ input_element = self.driver.find_element_by_xpath('//input[@class="input-2lFnByGCRh"]')
|
|
|
+ input_element.send_keys(Keys.BACKSPACE)
|
|
|
+ input_element.send_keys(now_time)
|
|
|
+ return now_time
|
|
|
+
|
|
|
def set_background_color(self):
|
|
|
color_buttons = self.driver.find_elements_by_class_name('adui-cp-picker')
|
|
|
c_buttons_can_use = []
|
|
@@ -314,78 +323,92 @@ class CreateAd:
|
|
|
logging.info(e)
|
|
|
logging.info('图片模块设置结束')
|
|
|
|
|
|
- def set_title(self, title_content):
|
|
|
- # 设置标题模块
|
|
|
+ def set_content(self, config_info):
|
|
|
+ # 设置文本模块
|
|
|
+ # 1.文本内容2.文本颜色3.是否加粗4.文本位置设置5.文本大小
|
|
|
+
|
|
|
+ # 设置文本内容
|
|
|
self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[2]/div[5]/div/div').click()
|
|
|
time.sleep(random.uniform(0.2, 0.3))
|
|
|
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(title_content)
|
|
|
+ _.send_keys(config_info['content'])
|
|
|
|
|
|
- color_buttons = self.driver.find_elements_by_class_name('adui-cp-picker')
|
|
|
- c_buttons_can_use = []
|
|
|
- for _ in color_buttons:
|
|
|
- if _.is_displayed() and _.is_enabled():
|
|
|
- c_buttons_can_use.append(_)
|
|
|
- c_buttons_can_use[1].click()
|
|
|
- time.sleep(random.uniform(0.2, 0.3))
|
|
|
+ # 设置颜色
|
|
|
+ if config_info['color'] != '595959':
|
|
|
+ color_buttons = self.driver.find_elements_by_class_name('adui-cp-picker')
|
|
|
+ c_buttons_can_use = []
|
|
|
+ for _ in color_buttons:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ c_buttons_can_use.append(_)
|
|
|
+ c_buttons_can_use[1].click()
|
|
|
+ time.sleep(random.uniform(0.2, 0.3))
|
|
|
|
|
|
- input_elements = self.driver.find_elements_by_tag_name('input')
|
|
|
- for _ in input_elements:
|
|
|
- if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '595959':
|
|
|
- _.click()
|
|
|
- _.send_keys('DE2821')
|
|
|
- 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()
|
|
|
- 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(_)
|
|
|
- loc_buttons_can_use[1].click()
|
|
|
+ input_elements = self.driver.find_elements_by_tag_name('input')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '595959':
|
|
|
+ _.click()
|
|
|
+ _.send_keys(config_info['color'])
|
|
|
|
|
|
- str_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-selection__rendered']")
|
|
|
- str_buttons_can_use = []
|
|
|
- for _ in str_buttons:
|
|
|
- if _.is_displayed() and _.is_enabled():
|
|
|
- str_buttons_can_use.append(_)
|
|
|
- str_buttons_can_use[1].click()
|
|
|
- time.sleep(random.uniform(1, 3))
|
|
|
+ # 设置是否加粗
|
|
|
+ if config_info['is_bold']:
|
|
|
+ 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()
|
|
|
|
|
|
- str_num_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-dropdown-menu-item']")
|
|
|
- str_num_can_use = []
|
|
|
- for _ in str_num_buttons:
|
|
|
- if _.is_displayed() and _.is_enabled():
|
|
|
- str_num_can_use.append(_)
|
|
|
- str_num_can_use[4].click()
|
|
|
+ # 设置文本位置
|
|
|
+ if config_info['loc'] != 'left':
|
|
|
+ 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':
|
|
|
+ loc_buttons_can_use[1].click()
|
|
|
+ if config_info['loc'] == 'right':
|
|
|
+ loc_buttons_can_use[2].click()
|
|
|
+
|
|
|
+ # 设置文本大小
|
|
|
+ if config_info['str_num'] != 15:
|
|
|
+ str_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-selection__rendered']")
|
|
|
+ str_buttons_can_use = []
|
|
|
+ for _ in str_buttons:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ str_buttons_can_use.append(_)
|
|
|
+ str_buttons_can_use[1].click()
|
|
|
+ time.sleep(random.uniform(1, 3))
|
|
|
|
|
|
- def set_content(self, content_content):
|
|
|
- # 输入文本内容
|
|
|
- self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[2]/div[5]/div/div').click()
|
|
|
- time.sleep(random.uniform(0.2, 0.3))
|
|
|
- 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(content_content)
|
|
|
- str_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-selection__rendered']")
|
|
|
- str_buttons_can_use = []
|
|
|
- for _ in str_buttons:
|
|
|
- if _.is_displayed() and _.is_enabled():
|
|
|
- str_buttons_can_use.append(_)
|
|
|
- str_buttons_can_use[1].click()
|
|
|
- time.sleep(random.uniform(1, 3))
|
|
|
- str_num_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-dropdown-menu-item']")
|
|
|
- str_num_can_use = []
|
|
|
- for _ in str_num_buttons:
|
|
|
- if _.is_displayed() and _.is_enabled():
|
|
|
- str_num_can_use.append(_)
|
|
|
- str_num_can_use[3].click()
|
|
|
+ str_num_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-dropdown-menu-item']")
|
|
|
+ str_num_can_use = []
|
|
|
+ for _ in str_num_buttons:
|
|
|
+ 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()
|
|
|
+
|
|
|
+ # 设置文本边距
|
|
|
+ if config_info['str_distance'][0] != 22 or config_info['str_distance'][1] != 22:
|
|
|
+ distance_buttons = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ distance_buttons_can_use = []
|
|
|
+ for _ in distance_buttons:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '22':
|
|
|
+ distance_buttons_can_use.append(_)
|
|
|
+ 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[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])
|
|
|
|
|
|
def set_follow_button(self, button_type):
|
|
|
# 设置关注按钮
|
|
|
+ # 1.设置button文本内容2.是否加粗3.设置字体颜色,边框颜色,填充色4.设置边距
|
|
|
+
|
|
|
self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[4]/div[2]/div/div').click()
|
|
|
if button_type == 1:
|
|
|
input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
@@ -475,9 +498,60 @@ class CreateAd:
|
|
|
size_buttons_can_use[1].send_keys(Keys.BACKSPACE)
|
|
|
size_buttons_can_use[1].send_keys('100')
|
|
|
|
|
|
- def set_movie(self):
|
|
|
- # 设置视频
|
|
|
- pass
|
|
|
+ def set_follow_button_(self, config_info):
|
|
|
+ # 设置关注按钮
|
|
|
+ # 1.设置button文本内容 2.是否加粗 3.设置字体颜色,边框颜色,填充色 4.设置边距
|
|
|
+
|
|
|
+ self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[4]/div[2]/div/div').click()
|
|
|
+ # 文本设置
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '关注公众号':
|
|
|
+ _.click()
|
|
|
+ _.clear()
|
|
|
+ for i in range(10):
|
|
|
+ _.send_keys(Keys.BACKSPACE)
|
|
|
+ _.send_keys(config_info['content'])
|
|
|
+
|
|
|
+ # 文本是否加粗
|
|
|
+ if config_info['is_bold']:
|
|
|
+ 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():
|
|
|
+ _.click()
|
|
|
+
|
|
|
+ # 颜色设置
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ input_elements_can_use = []
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and (
|
|
|
+ _.get_attribute("value") == '07C160' or _.get_attribute("value") == 'FFFFFF'):
|
|
|
+ input_elements_can_use.append(_)
|
|
|
+
|
|
|
+ input_elements_can_use[0].click()
|
|
|
+ input_elements_can_use[0].send_keys(config_info['color1'])
|
|
|
+ time.sleep(random.uniform(0.1, 0.5))
|
|
|
+ input_elements_can_use[1].click()
|
|
|
+ input_elements_can_use[1].send_keys(config_info['color2'])
|
|
|
+ time.sleep(random.uniform(0.1, 0.5))
|
|
|
+ input_elements_can_use[2].click()
|
|
|
+ input_elements_can_use[2].send_keys(config_info['color3'])
|
|
|
+ time.sleep(random.uniform(0.1, 0.5))
|
|
|
+
|
|
|
+ # 间隙设置
|
|
|
+ size_buttons = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ size_buttons_can_use = []
|
|
|
+ for _ in size_buttons:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '28':
|
|
|
+ size_buttons_can_use.append(_)
|
|
|
+ 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[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])
|
|
|
|
|
|
def set_text_button(self):
|
|
|
# 设置图文按钮
|
|
@@ -601,13 +675,14 @@ class CreateAd:
|
|
|
self.driver.execute_script('window.close();')
|
|
|
self.driver.switch_to.window(self.driver.window_handles[-1])
|
|
|
|
|
|
- def send_moive_spic(self):
|
|
|
- # 特殊情况下,上传本地视频
|
|
|
+ def set_share_content(self):
|
|
|
+ # TODO:设置分享标题,文本
|
|
|
pass
|
|
|
|
|
|
- def get_layout(self,layout):
|
|
|
+ def get_layout(self, layout):
|
|
|
# TODO:设置重试机制,然后错误后试错几次,查看是否成功
|
|
|
- # self.send_file_alone(layout)
|
|
|
+ self.send_file_alone(layout)
|
|
|
+ advertisement_sign = self.set_advertisement_sign()
|
|
|
self.set_head_assemb(layout[-1])
|
|
|
if -2 in layout.keys():
|
|
|
self.set_background_color()
|
|
@@ -618,13 +693,12 @@ class CreateAd:
|
|
|
info_v = info[info_key]
|
|
|
if info_key == 'page':
|
|
|
self.set_page(info_v)
|
|
|
- if info_key == 'title':
|
|
|
- self.set_title(info_v)
|
|
|
if info_key == 'content':
|
|
|
self.set_content(info_v)
|
|
|
if info_key == 'follow_button':
|
|
|
- self.set_follow_button(info_v)
|
|
|
+ self.set_follow_button_(info_v)
|
|
|
time.sleep(100)
|
|
|
+ return advertisement_sign
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
@@ -639,4 +713,3 @@ if __name__ == '__main__':
|
|
|
level=logging.INFO,
|
|
|
format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
|
|
|
)
|
|
|
-
|