添加日志
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import random
|
||||
import time
|
||||
import ui
|
||||
import common
|
||||
|
||||
log = common.get_logger("apps")
|
||||
|
||||
class Rule:
|
||||
def __init__(self):
|
||||
@@ -43,7 +46,7 @@ class Task:
|
||||
|
||||
@classmethod
|
||||
def watch_video(cls, name, rule, device):
|
||||
return cls(name, rule, lambda : device.swipe_up(120, 40))
|
||||
return cls(name, rule, lambda : device.swipe_up(150, 40))
|
||||
|
||||
@classmethod
|
||||
def read_book(cls, name, rule, device):
|
||||
@@ -54,9 +57,9 @@ class Task:
|
||||
return cls(name, rule, lambda : device.swipe_up(300, 300))
|
||||
|
||||
def start(self):
|
||||
print("开始执行任务:{}".format(self.name))
|
||||
log.info("开始执行任务:{}".format(self.name))
|
||||
_exec(self.rule, self.func, self.name)
|
||||
print("任务{}执行完毕".format(self.name))
|
||||
log.info("任务{}执行完毕".format(self.name))
|
||||
pass
|
||||
|
||||
def _exec(rule, func = [], log_prefix = "执行任务"):
|
||||
@@ -68,7 +71,7 @@ def _exec(rule, func = [], log_prefix = "执行任务"):
|
||||
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))
|
||||
log.info("{}:{}/{} ,停留 {} 秒".format(log_prefix, i, num, wait_time))
|
||||
if isinstance(func, list):
|
||||
for f in func:
|
||||
f()
|
||||
@@ -87,7 +90,7 @@ def _exec(rule, func = [], log_prefix = "执行任务"):
|
||||
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))
|
||||
log.info("{}:{}/{} ,停留 {} 秒".format(log_prefix, time_total, duration, wait_time))
|
||||
func()
|
||||
time.sleep(wait_time)
|
||||
time_total = round(time_total + wait_time, 2)
|
||||
@@ -101,8 +104,8 @@ class ToutiaoLite(_App):
|
||||
self.device = device
|
||||
|
||||
def open_treasure_box(action):
|
||||
print("开宝箱...")
|
||||
print("开宝箱完成...")
|
||||
log.info("开宝箱...")
|
||||
log.info("开宝箱完成...")
|
||||
|
||||
# 看广告
|
||||
def func_ad(self):
|
||||
|
21
script/common.py
Normal file
21
script/common.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import sys
|
||||
import logging
|
||||
|
||||
logger_level_relations = {
|
||||
'debug': logging.DEBUG,
|
||||
'info': logging.INFO,
|
||||
'warning': logging.WARNING,
|
||||
'error': logging.ERROR,
|
||||
'crit': logging.CRITICAL
|
||||
}
|
||||
|
||||
def get_logger(name : str, level : str = 'info'):
|
||||
|
||||
logger = logging.getLogger(name)
|
||||
logger.setLevel(logger_level_relations.get(level))
|
||||
ch = logging.StreamHandler(sys.stdout)
|
||||
ch.setLevel(logger_level_relations.get(level))
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
return logger
|
@@ -1,5 +1,8 @@
|
||||
import adb
|
||||
import random
|
||||
import common
|
||||
|
||||
log = common.get_logger("devices", "debug")
|
||||
|
||||
class _Action:
|
||||
def __init__(self, id, scr_w, scr_h):
|
||||
@@ -37,6 +40,7 @@ class _Action:
|
||||
x2 = x1 + int(random.uniform(-10, 10))
|
||||
y2 = y1 - dist + int(random.uniform(-10, 10))
|
||||
time = speed - int(random.uniform(-10, 10))
|
||||
log.debug("x1: {} , y1: {} , x2: {} , y2: {} , time: {}".format(x1, y1, x2, y2, time))
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 下滑
|
||||
@@ -46,6 +50,7 @@ class _Action:
|
||||
x2 = x1 + int(random.uniform(-10, 10))
|
||||
y2 = y1 + dist + int(random.uniform(-10, 10))
|
||||
time = speed + int(random.uniform(-10, 10))
|
||||
log.debug("x1: {} , y1: {} , x2: {} , y2: {} , time: {}".format(x1, y1, x2, y2, time))
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 左滑
|
||||
@@ -55,6 +60,7 @@ class _Action:
|
||||
x2 = x1 - dist + int(random.uniform(-10, 10))
|
||||
y2 = y1 + int(random.uniform(-10, 10))
|
||||
time = speed + int(random.uniform(-10, 10))
|
||||
log.debug("x1: {} , y1: {} , x2: {} , y2: {} , time: {}".format(x1, y1, x2, y2, time))
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 右滑
|
||||
@@ -64,6 +70,7 @@ class _Action:
|
||||
x2 = x1 + dist + int(random.uniform(-10, 10))
|
||||
y2 = y1 + int(random.uniform(-10, 10))
|
||||
time = speed + int(random.uniform(-10, 10))
|
||||
log.debug("x1: {} , y1: {} , x2: {} , y2: {} , time: {}".format(x1, y1, x2, y2, time))
|
||||
self.operator.swipe(x1, y1, x2, y2, time)
|
||||
|
||||
# 点击
|
||||
|
@@ -2,9 +2,11 @@ from devices import WikoHi70m
|
||||
import apps
|
||||
import random
|
||||
import threading
|
||||
import common
|
||||
|
||||
def main():
|
||||
|
||||
log = common.get_logger("main")
|
||||
try:
|
||||
|
||||
# adb_cmd.mobile_unlock()
|
||||
@@ -14,8 +16,8 @@ def main():
|
||||
|
||||
# 普通任务
|
||||
watchAdTask = apps.Task("连续看广告", apps.Rule.count(35, 45, 2), lambda : apps.ToutiaoLite(wikoHi70m).func_ad())
|
||||
watchVideoTask = apps.Task.watch_video("刷视频", apps.Rule.count(2000, 6, 2), wikoHi70m)
|
||||
readBookTask = apps.Task.read_book("看书", apps.Rule.count(1000, 5, 2), wikoHi70m)
|
||||
watchVideoTask = apps.Task.watch_video("刷视频", apps.Rule.count(1000, 6, 2), wikoHi70m)
|
||||
readBookTask = apps.Task.read_book("看书", apps.Rule.count(2000, 5, 2), wikoHi70m)
|
||||
browseTask = apps.Task.browse("逛街", apps.Rule.time(60, 4, 2), wikoHi70m)
|
||||
|
||||
# 窗口任务
|
||||
@@ -46,7 +48,7 @@ def main():
|
||||
# wikoHi70m.lock()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("程序被用户中断")
|
||||
log.info("程序被用户中断")
|
||||
|
||||
# 多任务同步执行
|
||||
def sync_task(task1, task2):
|
||||
|
Reference in New Issue
Block a user