161 lines
4.8 KiB
Python
161 lines
4.8 KiB
Python
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("看视频任务完成")
|
||
|
||
def read_book(self, rule):
|
||
print("开始看书任务...")
|
||
_exec(rule, lambda : self.device.swipe_left(300, 100), "看书中")
|
||
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("看视频任务完成")
|
||
|