手机自动化脚本

# !/usr/bin/python
# _*_ coding:utf-8 _*_

import os
import re
import time
from colorama import init

init(autoreset=True)
# 获取电脑屏幕的宽度
width = os.get_terminal_size().columns


# 自动wifi连接
def auto_wifi_connect():
    print("\033[0;32;40m自动连接wifi\033[0m".center(width, '*'))
    os.popen("adb push WifiConfigStore.xml /data/misc/wifi/")
    os.popen("adb reboot")
    # 计时
    index = 1
    while True:
        time.sleep(1)
        if len(get_devices_sn()) > 0:
            break
        else:
            # 最大等待时间1分钟
            if index == 90:
                print("\033[0;31;40m手机重启超时\033[0m".center(width, '*'))
                return
            index += 1
            continue
    os.popen("adb root")


# 打开飞行模式
def open_flight_mode():
    print("\033[0;32;40m打开飞行模式\033[0m".center(width, '*'))
    os.popen("adb shell settings put global airplane_mode_on 1")
    os.popen("adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true")


# 设置熄屏
def rest_screen():
    # 等待30分钟
    time.sleep(1800)
    print("\033[0;32;40m熄灭屏幕-等待30秒\033[0m".center(width, '*'))
    os.popen("adb shell input keyevent 26")


# 执行命令
def execute_command():
    print("\033[0;32;40m执行命令(location off and duraspeed off)\033[0m".center(width, '*'))
    os.popen("location off")
    os.popen("duraspeed off")


# 主函数
def main():
    print('''* 1.手机需要先连上wifi,然后输入"adb pull /data/misc/wifi/WifiConfigStore.xml"拉取出"WifiConfigStore.xml"文件。''')
    print('''* 2.将"WifiConfigStore.xml"文件放在zzt_auto.py(脚本)或zzt_auto.exe同级目录,未push文件的手机必须做一次。''')
    input_data = input('''* 请告诉我,需要push "WifiConfigStore.xml"文件到手机吗?这个过程会重启手机(Y/Enter)''')
    # 检测手机是否连接和获取sn号
    sn_list = get_devices_sn()
    if len(sn_list) < 1:
        print("\033[0;31;40m没有手机连接\033[0m".center(width, '*'))
        return
    print("\033[0;32;40mSN:{}\033[0m".format(sn_list[0]).center(width, '*'))
    # adb root
    os.popen("adb root")
    # 自动连接wifi
    if input_data == "Y" or input_data == "y":
        auto_wifi_connect()
    os.popen("adb shell svc wifi enable")
    # 打开飞行模式
    open_flight_mode()
    # 熄灭屏幕
    rest_screen()
    # 执行命令
    execute_command()
    # 结束
    print("\033[0;32;40m测试完成\033[0m".format(sn_list[0]).center(width, '*'))


# 获取SN号
def get_devices_sn():
    sn_list = []
    device_info = os.popen('adb devices').read()
    for line in device_info.splitlines():
        if line == 'List of devices attached':
            continue
        else:
            com = re.compile('(.*?)\tde.*?')
            sn = re.findall(com, line)
            for i in sn:
                sn_list.append(i)
    return sn_list


if __name__ == '__main__':
    try:
        main()
    except:
        input("输入任意字符结束")

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值