def main(self): # 判断杀软环境 # 360环境 # 启动下载器程序 self.start_app() wc(title_name).wait(60) self.make_dir() # 点击一键安装 self.first_button_click(xiazaiqi_anniu_path + "install.png", xiazaiqi_anniu_path + "install_bs.png", title_name) time.sleep(2) process_all_name = self.get_process() # 判断第三页按钮是否出现并点击安装完成 self.install_button_click( xiazaiqi_anniu_path + "install_success.png", xiazaiqi_anniu_path + "install_success_bs.png", title_name) time.sleep(3) # 杀软拦截截屏 self.environment360(process_all_name, title_name, 240) # 判断第三页是否有软件 # 有软件,等待进程结束继续重复以上步骤 # 无软件,结束任务 if title_name in self.get_process(): try: self.close_app(title_name) print("下载器已关闭") except: pass
def close_process(self, p): for pro in self.get_process(): if pro not in p: print("结束的进程名为%s" % pro) try: wc(pro).close() except: pass
def first_button_click(self, pic_name, pic_zh_name, title_app_name): wc(title_app_name).activate() # 截屏第一页 self.get_xiazaiqi_screen("第一页", title_name) time.sleep(1) try: button_down_pixel = pa.locateOnScreen(pic_name) x, y = pa.center(button_down_pixel) click(coords=(x, y)) except: button_down_pixel = pa.locateOnScreen(pic_zh_name) x, y = pa.center(button_down_pixel) click(coords=(x, y))
def install_button_click(self, pic_name, pic_zh_name, title_app_name): while True: # 激活软件窗口 wc(title_app_name).activate() if pa.locateOnScreen(pic_name) is not None: x, y = pa.center(pa.locateOnScreen(pic_name)) # 截屏第三页 self.get_xiazaiqi_screen("第三页", title_name) click(coords=(x, y)) break elif pa.locateOnScreen(pic_zh_name) is not None: x, y = pa.center(pa.locateOnScreen(pic_zh_name)) # 截屏第三页 self.get_xiazaiqi_screen("第三页", title_name) click(coords=(x, y)) break
def close_app(self, title_app_name): wc(title_app_name).kill()
def get_xiazaiqi_screen(self, name, title_app_name): x, y, x1, y1 = wc(title_app_name).getPos() w = x1 - x h = y1 - y pos = [x, y, w, h] self.get_screen(pos, name)