import os
import time
import subprocess
from threading import Thread

# adb 模拟滑动手势(以步长200 从坐标350,1580 滑动到350,680)
def adb_swipe(device):
    print(device)
    cmdStr = 'adb shell'
    if len(device) > 0:
        cmdStr = "adb -s {a} shell".format(a = device)

    while True:
        os.system(cmdStr + " input swipe 350 1580 350 680 200")
        time.sleep(2)
        os.system(cmdStr + " input swipe 350 680 350 1580 200")
        time.sleep(10 * 55)

def getphonelist():  # 获取手机设备
    cmd = r'adb devices'  # % apk_file
    pr = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    pr.wait()  # 不会马上返回输出的命令，需要等待
    out = pr.stdout.readlines()  # out = pr.stdout.read().decode("UTF-8")
    devices = []
    for i in (out)[1:-1]:
        device = str(i).split("\\")[0].split("'")[-1]
        devices.append(device)
    return devices  # 手机设备列表


if __name__ == "__main__":
    str2 = input("1：usb连接 2：wifi连接：/n")
    threads = []
    for i in range(len(getphonelist())):
        tempThread = Thread(target=adb_swipe, args=(getphonelist()[i],))
        tempThread.start()
        print(i)


