py脚本
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
script/__pycache__/
|
66
script/adb.py
Normal file
66
script/adb.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import subprocess
|
||||
import re
|
||||
import threading
|
||||
|
||||
lock = threading.Lock()
|
||||
|
||||
# 获取连接的设备
|
||||
def device_get():
|
||||
cmd = "adb devices"
|
||||
result = subprocess.run(cmd.split(" "), capture_output=True, text=True)
|
||||
stdout = result.stdout
|
||||
# print("------ stdout --------")
|
||||
# print(stdout)
|
||||
# print("------ stdout --------")
|
||||
devices = []
|
||||
for line in stdout.split("\n")[1:]:
|
||||
line = line.strip()
|
||||
if line != "":
|
||||
match = re.match(r"(\S+)", line)
|
||||
devices.append(match.group(1))
|
||||
return devices
|
||||
|
||||
# 连接远程设备
|
||||
def device_connect(ip, port = 5555):
|
||||
cmd = "adb connect {}:{}".format(ip, port)
|
||||
result = subprocess.run(cmd.split(" "), capture_output=True, text=True)
|
||||
stdout = result.stdout
|
||||
# print(stdout)
|
||||
return stdout.startswith("connected to")
|
||||
|
||||
# 断开设备
|
||||
def device_disconnect(ip, port = 5555):
|
||||
cmd = "adb disconnect {}:{}".format(ip, port)
|
||||
result = subprocess.run(cmd.split(" "), capture_output=True, text=True)
|
||||
stdout = result.stdout
|
||||
# print(stdout)
|
||||
return stdout.startswith("disconnected")
|
||||
|
||||
class Operator:
|
||||
|
||||
def __init__(self, id):
|
||||
self.id = id
|
||||
|
||||
def home(self):
|
||||
cmd = "adb -s {} shell input keyevent 3".format(self.id)
|
||||
self._run(cmd)
|
||||
|
||||
def back(self):
|
||||
cmd = "adb -s {} shell input keyevent 4".format(self.id)
|
||||
self._run(cmd)
|
||||
|
||||
def power(self):
|
||||
cmd = "adb -s {} shell input keyevent 26".format(self.id)
|
||||
self._run(cmd)
|
||||
|
||||
def touch(self, x, y):
|
||||
cmd = "adb -s {} shell input tap {} {}".format(self.id, x, y)
|
||||
self._run(cmd)
|
||||
|
||||
def swipe(self, startX, startY, endX, endY, time):
|
||||
cmd = "adb -s {} shell input swipe {} {} {} {} {}".format(self.id, startX, startY, endX, endY, time)
|
||||
self._run(cmd)
|
||||
|
||||
def _run(self, cmd):
|
||||
with lock:
|
||||
subprocess.run(cmd.split(" "))
|
155
script/apps.py
Normal file
155
script/apps.py
Normal file
@@ -0,0 +1,155 @@
|
||||
import random
|
||||
import time
|
||||
import ui
|
||||
|
||||
class Rule:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def count(self, num, interval, factor = 0):
|
||||
self.num = num
|
||||
self.interval = interval
|
||||
self.factor = factor
|
||||
return self
|
||||
|
||||
@classmethod
|
||||
def time(self, duration, interval, factor = 0):
|
||||
self.duration = duration
|
||||
self.interval = interval
|
||||
self.factor = factor
|
||||
return self
|
||||
|
||||
class _App:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def name(self):
|
||||
return self.name
|
||||
|
||||
def open_app(self):
|
||||
pass
|
||||
|
||||
def open_function(self):
|
||||
pass
|
||||
|
||||
def _exec(rule, func, log_prefix = ""):
|
||||
factor = getattr(rule, "factor")
|
||||
if hasattr(rule, "num"):
|
||||
num = getattr(rule, "num")
|
||||
i = 1
|
||||
while i <= num:
|
||||
wait_time = getattr(rule, "interval")
|
||||
if factor > 0:
|
||||
wait_time = round(random.uniform(wait_time - factor, wait_time + factor), 2)
|
||||
print("{}:{}/{} ,停留 {} 秒".format(log_prefix, i, num, wait_time))
|
||||
func()
|
||||
time.sleep(wait_time)
|
||||
i += 1
|
||||
return True
|
||||
|
||||
if hasattr(rule, "time"):
|
||||
duration = getattr(rule, "duration")
|
||||
time_total = 0
|
||||
while time_total < duration:
|
||||
wait_time = getattr(rule, "interval")
|
||||
if factor > 0:
|
||||
wait_time = round(random.uniform(wait_time - factor, wait_time + factor), 2)
|
||||
if time_total + wait_time > duration:
|
||||
wait_time = round(duration - time_total, 2)
|
||||
print("{}:{}/{} ,停留 {} 秒".format(log_prefix, time_total, duration, wait_time))
|
||||
func()
|
||||
time.sleep(wait_time)
|
||||
time_total = round(time_total + wait_time, 2)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
class ToutiaoLite(_App):
|
||||
def __init__(self, device):
|
||||
_App.__init__(self, "头条极速版")
|
||||
self.device = device
|
||||
|
||||
def open_treasure_box(action):
|
||||
print("开宝箱...")
|
||||
print("开宝箱完成...")
|
||||
|
||||
def watch_video(self, rule):
|
||||
print("开始看视频任务...")
|
||||
_exec(rule, lambda : self.device.swipe_up(150, 50), "看视频中")
|
||||
print("看视频任务完成")
|
||||
|
||||
def watch_ad(self, rule):
|
||||
print("开始看广告任务...")
|
||||
# 0.3
|
||||
def func():
|
||||
button = ui.Button(240, 450, 850, 920)
|
||||
point = button.get_point()
|
||||
self.device.back()
|
||||
self.device.back() # 防止自动进入直播界面
|
||||
self.device.click(point)
|
||||
|
||||
_exec(rule, lambda : func(), "看广告中")
|
||||
|
||||
print("看广告任务完成...")
|
||||
|
||||
class DouyinLite(_App):
|
||||
def __init__(self, device):
|
||||
_App.__init__(self, "抖音极速版")
|
||||
self.device = device
|
||||
|
||||
def watch_video(self, rule):
|
||||
print("开始看视频任务...")
|
||||
_exec(rule, lambda : self.device.swipe_up(120, 80), "看视频中")
|
||||
print("看视频任务完成")
|
||||
|
||||
class KuaishouLite(_App):
|
||||
def __init__(self, device):
|
||||
_App.__init__(self, "快手极速版")
|
||||
self.device = device
|
||||
|
||||
def watch_video(self, rule):
|
||||
print("开始看视频任务...")
|
||||
_exec(rule, lambda : self.device.swipe_up(120, 80), "看视频中")
|
||||
print("看视频任务完成")
|
||||
|
||||
class TomatoListen(_App):
|
||||
def __init__(self, device):
|
||||
_App.__init__(self, "番茄畅听")
|
||||
self.device = device
|
||||
|
||||
def watch_video(self, rule):
|
||||
print("开始看视频任务...")
|
||||
_exec(rule, lambda : self.device.swipe_up(120, 80), "看视频中")
|
||||
print("看视频任务完成")
|
||||
|
||||
def read_book(self, rule):
|
||||
print("开始看书任务...")
|
||||
_exec(rule, lambda : self.device.swipe_left(300, 100), "看书中")
|
||||
print("看书任务完成")
|
||||
|
||||
class TomatoFiction(_App):
|
||||
def __init__(self, device):
|
||||
_App.__init__(self, "番茄小说")
|
||||
self.device = device
|
||||
|
||||
def read_book(self, rule):
|
||||
print("开始看书任务...")
|
||||
_exec(rule, lambda : self.device.swipe_left(300, 100), "看书中")
|
||||
print("看书任务完成")
|
||||
|
||||
def watch_video(self, rule):
|
||||
print("开始看视频任务...")
|
||||
_exec(rule, lambda : self.device.swipe_up(120, 80), "看视频中")
|
||||
print("看视频任务完成")
|
||||
|
||||
class Alipay(_App):
|
||||
def __init__(self, device):
|
||||
_App.__init__(self, "支付宝")
|
||||
self.device = device
|
||||
|
||||
def watch_video(self, rule):
|
||||
print("开始看视频任务...")
|
||||
_exec(rule, lambda : self.device.swipe_up(120, 80), "看视频中")
|
||||
print("看视频任务完成")
|
||||
|
90
script/devices.py
Normal file
90
script/devices.py
Normal file
@@ -0,0 +1,90 @@
|
||||
import adb
|
||||
import random
|
||||
|
||||
class _Action:
|
||||
def __init__(self, id, scr_w, scr_h):
|
||||
self.id = id
|
||||
self.scr_w = scr_w
|
||||
self.scr_h = scr_h
|
||||
self.operator = adb.Operator(self.id)
|
||||
|
||||
# 唤醒
|
||||
def wakeup(self):
|
||||
pass
|
||||
|
||||
# 解锁
|
||||
def unlock(self):
|
||||
pass
|
||||
|
||||
# 锁屏
|
||||
def lock(self):
|
||||
self.operator.home()
|
||||
self.operator.power()
|
||||
|
||||
# 返回
|
||||
def back(self):
|
||||
self.operator.back()
|
||||
|
||||
# 划动
|
||||
def swipe(self, x1, y1, x2, y2, time):
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 上滑
|
||||
def swipe_up(self, dist, speed):
|
||||
|
||||
x1 = int(self.scr_w * 0.25) + int(random.uniform(-10, 10))
|
||||
x2 = x1 + int(random.uniform(-10, 10))
|
||||
y1 = int(self.scr_w * 0.7) + int(random.uniform(-10, 10))
|
||||
y2 = y1 - dist + int(random.uniform(-10, 10))
|
||||
time = speed - int(random.uniform(-10, 10))
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 下滑
|
||||
def swipe_down(self, dist, speed):
|
||||
x1 = int(self.scr_w * 0.75) + int(random.uniform(-10, 10))
|
||||
x2 = x1 + int(random.uniform(-10, 10))
|
||||
y1 = int(self.scr_w * 0.5) + int(random.uniform(-10, 10))
|
||||
y2 = y1 + dist + int(random.uniform(-10, 10))
|
||||
time = speed + int(random.uniform(-10, 10))
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 左滑
|
||||
def swipe_left(self, dist, speed):
|
||||
x1 = int(self.scr_w * 0.7) + int(random.uniform(-10, 10))
|
||||
x2 = x1 - dist + int(random.uniform(-10, 10))
|
||||
y1 = int(self.scr_w * 0.75) + int(random.uniform(-10, 10))
|
||||
y2 = y1 + int(random.uniform(-10, 10))
|
||||
time = speed + int(random.uniform(-10, 10))
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 右滑
|
||||
def swipe_right(self, dist, speed):
|
||||
x1 = int(self.scr_w * 0.25) + int(random.uniform(-10, 10))
|
||||
x2 = x1 + dist + int(random.uniform(-10, 10))
|
||||
y1 = int(self.scr_w * 0.75) + int(random.uniform(-10, 10))
|
||||
y2 = y1 + int(random.uniform(-10, 10))
|
||||
time = speed + int(random.uniform(-10, 10))
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 点击
|
||||
def click(self, point):
|
||||
self.operator.touch(point.x, point.y)
|
||||
|
||||
class _Device(_Action):
|
||||
|
||||
def __init__(self, id, scr_w, scr_h):
|
||||
super().__init__(id, scr_w, scr_h)
|
||||
self.id = id
|
||||
self.scr_w = scr_w
|
||||
self.scr_h = scr_h
|
||||
self.apps = []
|
||||
|
||||
def screen_width(self):
|
||||
return self.scr_w
|
||||
|
||||
def screen_height(self):
|
||||
return self.scr_h
|
||||
|
||||
class WikoHi70m(_Device):
|
||||
def __init__(self, id):
|
||||
super().__init__(id, 900, 1600)
|
62
script/main.py
Normal file
62
script/main.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from devices import WikoHi70m
|
||||
import apps
|
||||
import random
|
||||
|
||||
def app_custom(device):
|
||||
# 上滑视频
|
||||
device.swipe(240 + int(random.uniform(-10, 10)), 1200 + int(random.uniform(-10, 10)), 240 + int(random.uniform(-10, 10)), 1100 + int(random.uniform(-10, 10)), 50)
|
||||
# 上滑浏览(小窗口)
|
||||
# device.swipe(450 + int(random.uniform(-10, 10)), 400 + int(random.uniform(-10, 10)), 450 + int(random.uniform(-10, 10)), 200 + int(random.uniform(-10, 10)), 300)
|
||||
# 上滑视频(小窗口)
|
||||
device.swipe(450 + int(random.uniform(-10, 10)), 400 + int(random.uniform(-10, 10)), 450 + int(random.uniform(-10, 10)), 200 + int(random.uniform(-10, 10)), 50)
|
||||
# 左滑(小窗口)
|
||||
# device.swipe(600 + int(random.uniform(-10, 10)), 400 + int(random.uniform(-10, 10)), 400 + int(random.uniform(-10, 10)), 400 + int(random.uniform(-10, 10)), 80)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
# adb_cmd.mobile_unlock()
|
||||
|
||||
try:
|
||||
|
||||
wikoHi70m = WikoHi70m('3URNU24803102309')
|
||||
|
||||
# apps._exec(apps.Rule.count(500, 5, 2), lambda : app_custom(wikoHi70m), "任务执行中")
|
||||
|
||||
# 快手
|
||||
# kuaishouLite = apps.KuaishouLite(wikoHi70m)
|
||||
# kuaishouLite.watch_video(apps.Rule.count(500, 10, 2))
|
||||
|
||||
# 抖音
|
||||
# douyinLite = apps.DouyinLite(wikoHi70m)
|
||||
# 视频红包
|
||||
# douyinLite.watch_video(apps.Rule.count(1000, 7, 2))
|
||||
|
||||
# 支付宝
|
||||
# alipay = apps.Alipay(wikoHi70m)
|
||||
# 视频红包
|
||||
# alipay.watch_video(apps.Rule.count(1000, 7, 2))
|
||||
|
||||
# 头条
|
||||
# toutiaoLite = apps.ToutiaoLite(wikoHi70m)
|
||||
# toutiaoLite.watch_ad(apps.Rule.count(500, 10, 2))
|
||||
|
||||
# 番茄畅听
|
||||
# tomatoListen = apps.TomatoListen(wikoHi70m)
|
||||
# tomatoListen.read_book(apps.Rule.count(1000, 5, 2))
|
||||
# tomatoListen.watch_video(apps.Rule.count(500, 10, 2))
|
||||
|
||||
# 番茄小说
|
||||
tomatoFiction = apps.TomatoFiction(wikoHi70m)
|
||||
tomatoFiction.read_book(apps.Rule.count(1000, 5, 2))
|
||||
# tomatoFiction.watch_video(apps.Rule.count(500, 10, 2))
|
||||
|
||||
# 任务完成锁屏
|
||||
wikoHi70m.lock()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("程序被用户中断")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
25
script/ui.py
Normal file
25
script/ui.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import random
|
||||
|
||||
# 位置
|
||||
class Point:
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
# 按纽
|
||||
class Button:
|
||||
def __init__(self, x, y, w = 0, h = 0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.w = w
|
||||
self.h = h
|
||||
|
||||
def get_point(self, ran = True):
|
||||
if ran == True and self.w > 0 and self.h > 0:
|
||||
return Point(self.x + int(random.uniform(self.w * 4, self.w * 0.7)), self.y + int(random.uniform(self.h * 0.4, self.h * 0.7)))
|
||||
else:
|
||||
return Point(self.x, self.y)
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user