From 79dce0e1520435c682734c65aed5db3fb944c6f7 Mon Sep 17 00:00:00 2001 From: ssss134 <1340554713@qq.com> Date: Sat, 19 Oct 2024 19:00:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=97=A0=E9=99=90?= =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 7ee85b53..b97df5f9 100644 --- a/main.py +++ b/main.py @@ -29,12 +29,28 @@ def init_config(): else: return (args.username, args.password, args.list.split(",") if args.list else None, int(args.speed) if args.speed else 1,None) +class RollBackManager: + def __init__(self) -> None: + self.rollback_times = 0 + self.rollback_id = "" + def reset_times(self,id:str) -> int: + if id == self.rollback_id: + self.rollback_times = 0 + def add_times(self,id:str) -> None: + if id == self.rollback_id and self.rollback_times == 3: + raise Exception("回滚次数已达3次,请手动检查学习通任务点完成情况") + elif id != self.rollback_id: + # 新job + self.rollback_id = id + self.rollback_times = 1 + else: + self.rollback_times += 1 + if __name__ == '__main__': try: # 避免异常的无限回滚 - ROLLBACK_TIMES = 0 # 回滚计数器 - + RB = RollBackManager() # 初始化登录信息 username, password, course_list, speed,tiku_config= init_config() # 规范化播放速度的输入值 @@ -98,13 +114,11 @@ def init_config(): # 未启用题库或未开启题库提交,章节检测未完成会导致无法开始下一章,直接退出 logger.error(f"章节未开启,可能由于上一章节的章节检测未完成,请手动完成并提交再重试,或者开启题库并启用提交") break - if ROLLBACK_TIMES == 3: - raise Exception("回滚次数已达3次,请手动检查学习通任务点完成情况") - ROLLBACK_TIMES +=1 + RB.add_times(point["id"]) continue - # 正常获取,重置回滚计数器 - ROLLBACK_TIMES = 0 + # 正常获取,尝试重置回滚次数 + RB.reset_times(point["id"]) # 可能存在章节无任何内容的情况 if not jobs: