python pywinauto自动批量安装yalu设备傻瓜式操作

前言:

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

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

功能:

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

需求:

1.自动打开应用程序

python pywinauto自动批量安装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... 并写入安装包路径
python pywinauto自动批量安装yalu设备傻瓜式操作_第2张图片
python pywinauto自动批量安装yalu设备傻瓜式操作_第3张图片
    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

 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路径

 

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

python pywinauto自动批量安装yalu设备傻瓜式操作_第4张图片

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)


完整代码:

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

你可能感兴趣的:(python自动化)