当前位置:   article > 正文

python pywinauto自动批量安装yalu设备傻瓜式操作_pywinauto.findbestmatch.matcherror怎样使用try

pywinauto.findbestmatch.matcherror怎样使用try

前言:

   因为是自学python,搞这个东西弄了蛮长时间,幸好有朋友们的帮助。直到今天才基本弄好。还有一些地方有缺陷,不过我

 要换项目玩了,所以就不继续优化了。

功能:

   打开程序,检测插入电脑的手机设备,逐个安装yalu包

需求:

1.自动打开应用程序

app = Application().start(r'C:\Users\123\Desktop\Impactor_0.9.43\Impactor.exe')#打开程序
cyd_spec = app.window(title='Cydia Impactor')#定位窗口

 

 2.获取列表框里的设备信息

 

   info = app['Cydia Impactor']['ComboBox2'].texts()
 info = {}.fromkeys(info).keys() #去重复
 
3.设置循环条件,打开菜单 Device->Install Package... 并写入安装包路径
  1. while True:
  2. #遍历得到设备信息无限循环,判断以安装过的不在安装,设备拔下再插入则重新安装
  3. info = app['Cydia Impactor']['ComboBox2'].texts()
  4. info = {}.fromkeys(info).keys() #去重复
  5. for ab in exists:
  6. if ab not in info:
  7. exists.remove(ab)
  8. for aa in info:
  9. if aa != '' and '?' not in aa and aa not in exists:
  10. exists.append(aa)
  11. yalu_auto()
  12. else:
  13. continue
  14.  cyd_spec.menu_select(r"Device->Install Package...") # 找到安装菜单 
  15. cyd_open = app['Select package.']#打开Select package界面
  16. cyd_open.Edit.set_text(r'D:\work\work\yalu102_beta7.ipa')#写入yalu路径

 

4.连接数据库,输入账号和密码。用过的账号状态由0变为1不再使用

  1. cyd_open['打开'].click()#点击打开
  2. id = app['Apple ID Username']#定位 Apple ID Username界面
  3. time.sleep(1)
  4. un = ab.cursor()#数据库游标
  5. time.sleep(1)
  6. un.execute('SELECT * FROM catalog')#查询 catalog表数据
  7. #得到账号和密码
  1. for i in un.fetchall():
  2. if i[2] == 0:
  3. us = i[0]
  4. ps = i[1]
  5. print(us)
  1. break
  2. #如果不能点击‘打开’按钮,则重新尝试,输入账号和密码
  1. try:
  2. cyd_open['打开'].click()
  3. time.sleep(1)
  4. id.Edit.set_text(us)
  5. time.sleep(1)
  6. print(us)
  7. id['OK'].click()
  8. id.Edit.set_text(ps)
  9. id['OK'].click()
  10. except NameError as e :
  11. cyd_open['打开'].click()
  12. print('Account exhausted')
  1. except pywinauto.timings.TimeoutError and pywinauto.findbestmatch.MatchError as ee:
  2. pass
  3. except pywinauto.findbestmatch.MatchError as eee:
  4. app = Application().start(r'C:\Users\123\Desktop\Impactor_0.9.43\Impactor.exe')
  1. #将使用过的账号和密码状态改为1
  2. un.execute("UPDATE catalog SET status=1 WHERE user='%s'" % (us))
  3. ab.commit()
  4. time.sleep(1)


完整代码:

import time
import sqlite3
import warnings
import pywinauto
from pywinauto.application import Application

ab = sqlite3.connect(r'D:\work\work\iss.db')#数据库路径

#自动批量安装yalu
def yalu_auto():
    app = Application().start(r'C:\Users\123\Desktop\Impactor_0.9.43\Impactor.exe')#打开程序
    cyd_spec = app.window(title='Cydia Impactor')#定位窗口

    cyd_spec.menu_select(r"Device->Install Package...")  # 找到安装菜单
    cyd_open = app['Select package.']#打开Select package界面
    cyd_open.Edit.set_text(r'D:\work\work\yalu102_beta7.ipa')#写入yalu路径

    cyd_open['打开'].click()#点击打开
    id = app['Apple ID Username']#定位 Apple ID Username界面
    time.sleep(1)
    un = ab.cursor()#数据库游标
    time.sleep(1)
    un.execute('SELECT * FROM catalog')#查询 catalog表数据

    #得到账号和密码
    for i in un.fetchall():
        if i[2] == 0:
            us = i[0]
            ps = i[1]
            print(us)
            break

    #如果不能点击‘打开’按钮,则重新尝试,输入账号和密码
    try:

        cyd_open['打开'].click()
        time.sleep(1)
        id.Edit.set_text(us)
        time.sleep(1)
        print(us)
        id['OK'].click()

        id.Edit.set_text(ps)
        id['OK'].click()

    except  NameError as e :
        cyd_open['打开'].click()
        print('Account exhausted')

    except pywinauto.timings.TimeoutError and pywinauto.findbestmatch.MatchError as ee:
        pass

    except pywinauto.findbestmatch.MatchError as eee:
        app = Application().start(r'C:\Users\123\Desktop\Impactor_0.9.43\Impactor.exe')

    #将使用过的账号和密码状态改为1
    un.execute("UPDATE catalog SET status=1 WHERE user='%s'" % (us))
    ab.commit()
    time.sleep(1)

def yalu():
    warnings.filterwarnings('ignore')
    app = Application().start(r'C:\Users\123\Desktop\Impactor_0.9.43\Impactor.exe')  # 打开程序
    cyd_spec = app.window(title='Cydia Impactor')  # 定位窗口
    exists = []

    while True:
        #遍历得到设备信息无限循环,判断以安装过的不在安装,设备拔下再插入则重新安装
        info = app['Cydia Impactor']['ComboBox2'].texts()
        info = {}.fromkeys(info).keys() #去重复
        for ab in exists:
            if ab not in info:
                exists.remove(ab)
        for aa in info:
            if aa != '' and '?' not in aa and aa not in exists:
                exists.append(aa)
                yalu_auto()
            else:
                continue


if __name__ == '__main__':
    #调用函数
    yalu()



感谢:

YAN MEI

ZONGSHENG HE

繁华故事

快到碗里来 °、Jxx

wrtydyuh

附之前学习过的几个作者发表的 pywinauto链接:

  http://blog.csdn.net/shawpan/article/details/78170067

  http://blog.csdn.net/HuangZhang_123/article/details/69525381?locationNum=4

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/121324
推荐阅读
相关标签
  

闽ICP备14008679号