1 Star 0 Fork 10

godxkey/薅羊毛

forked from hotootop/薅羊毛 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
base.py 4.12 KB
一键复制 编辑 原始数据 按行查看 历史
hotootop 提交于 2021-02-02 11:09 . 主要代码
import threading
import time
from time import sleep
class RetryException(Exception):
"""多次重试未能如愿,抛出错误重启App"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class TaskException(Exception):
"""浏览内容循环时主动抛出,以去做任务"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class SwitchException(Exception):
"""抛出错误,切换app"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class TimedException(Exception):
"""抛出错误,执行时间任务"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class DoneException(Exception):
"""滑动错误,此错误为浏览内容时,却未能正确进入浏览内容界面"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class PeriodException(Exception):
"""抛出错误,执行时间任务"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class FindException(Exception):
"""滑动错误,此错误为浏览内容时,却未能正确进入浏览内容界面"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class DayException(Exception):
"""一天结束后,报错以重新开始"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class NightException(Exception):
"""一天结束后,报错以重新开始"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class HourException(Exception):
"""小时任务"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
class StopException(Exception):
"""小时任务"""
def __init__(self, info=''):
self.info = info
def __str__(self):
return self.info
def switch_task(task_control, app_name, after_work=None):
"""在循环中使用,以切换程序"""
if task_control.get(app_name) == '跨夜':
raise NightException
elif task_control.get(app_name) == '定时':
raise TimedException
elif task_control.get(app_name) == '下班':
if after_work:
after_work()
raise DoneException
elif task_control.get(app_name) == '周期':
raise PeriodException
elif task_control.get(app_name) == '天':
raise DayException
elif task_control.get(app_name) == '小时':
raise HourException()
elif task_control.get(app_name) == '停止':
raise StopException
class MyTimer(threading.Thread):
def __init__(self, seconds, mytarget, myargs=None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__flag = threading.Event() # 用于暂停线程的标识
self.__flag.set() # 设置为True
self.__running = threading.Event() # 用C于停止线程的标识
self.__running.set() # 将running设置为True
self.seconds = seconds
self.mytarget = mytarget
self.myargs = myargs
def run(self):
while self.__running.isSet():
self.__flag.wait() # 为True时立即返回, 为False时阻塞直到内部的标识位为True后返回
sleep(self.seconds)
if self.myargs:
self.mytarget(*self.myargs)
else:
self.mytarget()
def pause(self):
self.__flag.clear() # 设置为False, 让线程阻塞
def resume(self):
self.__flag.set() # 设置为True, 让线程停止阻塞
def stop(self):
self.__flag.set() # 将线程从暂停状态恢复, 如何已经暂停的话
self.__running.clear() # 设置为False
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xipis/collect-wool.git
git@gitee.com:xipis/collect-wool.git
xipis
collect-wool
薅羊毛
master

搜索帮助