diff --git a/main.py b/main.py index afc3d29..862a26f 100644 --- a/main.py +++ b/main.py @@ -67,11 +67,23 @@ class TimeChecker: end_time = datetime.datetime.strptime(times[1], "%H:%M") self.rest_lst.append((start_time, end_time)) logger.info("时间检查器初始化完成") - - def rest_time(self) -> int: ... + def rest_last_time(self) -> int: + """课间剩多久""" + if not self.during_rest(): + return 0 + now = datetime.datetime.now() + now_rest = [end_time for start_time, end_time in self.rest_lst if start_time <= now <= end_time] + if not now_rest: + return 0 + return (now_rest[0] - now).seconds - def class_time(self) -> int: ... + + def during_rest(self) -> bool: + now = datetime.datetime.now() + return any(start_time <= now <= end_time for start_time, end_time in self.rest_lst) + + def is_during_class(self) -> int: ... TIME_CHCKER = TimeChecker() @@ -1531,16 +1543,10 @@ def choice(fromwhere): try: try: if zz != fi[1]: - if rest(): - on_button_click( - "人名单文件的sha256值\n与上次不一致。\n请确认人名单是否被篡改。\n按确定以继续。", - "", - ) - elif not rest(): - on_button_click( - "人名单文件的sha256值\n与上次不一致。\n请确认人名单是否被篡改。\n按确定以继续。", - "pppp", - ) + on_button_click( + "人名单文件的sha256值\n与上次不一致。\n请确认人名单是否被篡改。\n按确定以继续。", + "" if TIME_CHCKER.during_rest() else "pppp", + ) else: password = True except: @@ -1548,7 +1554,7 @@ def choice(fromwhere): password = True except: pass - if rest() or (not rest() and password): + if TIME_CHCKER.during_rest() or password: logger.info("人名单sha256:" + file_sha256(NAME_LST_PATH)) logger.info(f"当前有{len(g_list)}人") password = False @@ -1565,20 +1571,14 @@ def choice(fromwhere): sha = file_sha256(r"support/record.txt") + "\n" try: if ooo != sha: - if rest(): - on_button_click( - "抽中记录的sha256值\n与上次不一致。\n请确认记录是否被篡改。\n按确定以继续。", - "", - ) - elif not rest(): - on_button_click( - "抽中记录的sha256值\n与上次不一致。\n请确认记录是否被篡改。\n按确定以继续。", - "pppp", - ) + on_button_click( + "抽中记录的sha256值\n与上次不一致。\n请确认记录是否被篡改。\n按确定以继续。", + "" if TIME_CHCKER.during_rest() else "pppp", + ) else: password = True - if (rest()) or (not rest() and password): - logger.info(f'操作后sha256:{file_sha256(r"support/record.txt")}') + if TIME_CHCKER.during_rest() or password: + logger.info(f"操作后sha256:{file_sha256(r'support/record.txt')}") password = False except: pass @@ -1593,19 +1593,13 @@ def choice(fromwhere): sha = file_sha256(r"support/journal.log") + "\n" try: if jourlog != sha: - if rest(): - on_button_click( - "日志的sha256值\n与程序自动操作的不一致。\n请确认记录是否被篡改。\n按确定以继续。", - "", - ) - elif not rest(): - on_button_click( - "日志的sha256值\n与程序自动操作的不一致。\n请确认记录是否被篡改。\n按确定以继续。", - "pppp", - ) + on_button_click( + "日志的sha256值\n与程序自动操作的不一致。\n请确认记录是否被篡改。\n按确定以继续。", + "" if TIME_CHCKER.during_rest() else "pppp", + ) else: password = True - if (rest()) or (not rest() and password): + if TIME_CHCKER.during_rest() or password: password = False except: pass @@ -2108,4 +2102,4 @@ t3 = threading.Thread(target=bsy, name="bsy") t1.start() # 开始运行t1线程 time.sleep(5) t2.start() # 开始运行t2线程 -# t3.start() +t3.start()