添加日志
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):
|
||||
|
Reference in New Issue
Block a user