impo rt adbutils
import os
import datetime
import time
class OriginOS_Platform_Tools:
def __init__(self,address,port='5555'):
if port:
tcpip='{ip}:{port}'.format(ip=address,port=port)
else:
tcpip=address# 非IP地址是 将port值设置为None
self.tcpip=tcpip
adb = adbutils.AdbClient(host="127.0.0.1", port=5037)
self.device = adb.device(self.tcpip)
output = adb.connect(tcpip)
# print(output)
self.width,self.height=self.device.window_size()
def swipe_ext(self,direction,scale=0.9,loc=0.5,duration=0.5):
# 默认0.9, 滑动距离为屏幕宽度的90% duration 默认0.5s
width=self.width
height=self.height
d=self.device
if direction=='up':
sx,ex=width*loc,width*loc
sy,ey=(height-(height*scale))/2+height*scale,(height-(height*scale))/2
elif direction=='down':
sx,ex=width*loc,width*loc
sy,ey=(height-(height*scale))/2,(height-(height*scale))/2+height*scale
elif direction=='right':
sy,ey=height*loc,height*loc
sx,ex=(width-(width*scale))/2,(width-(width*scale))/2+width*scale
elif direction=='left':
sy,ey=height*loc,height*loc
sx,ex=(width-(width*scale))/2+width*scale,(width-(width*scale))/2
d.swipe(sx, sy, ex, ey, duration)
return (sx, sy, ex, ey)
def timepiece(sefl,seconds,fps=5):
'''
倒计时:秒
刷新率:1秒内更新次数
'''
on_time=datetime.datetime.now()+datetime.timedelta(seconds=seconds)
while on_time > datetime.datetime.now():
total_seconds=(on_time-datetime.datetime.now()).total_seconds()
print('{: ^3}秒倒计时:{: ^6.2f}秒'.format(seconds,total_seconds),end='
')
time.sleep(1/fps)
else:
print('{: ^3}秒倒计时:{: ^6.2f}秒'.format(seconds,0),end='
')
OriginOS3=OriginOS_Platform_Tools('192.168.1.2')
import random
for i in range(100000):
OriginOS3.swipe_ext('left',0.75,0.85)# vivo浏览器小说
OriginOS3.swipe_ext('left',0.4)# 抖音极速版悬浮窗口
seconds=random.randint(9,10)
OriginOS3.timepiece(seconds,fps=5)