From ba7b9a61d58ae36acf3ffb03207839956bc4fd27 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 4 Nov 2024 00:24:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E5=85=88=E5=A3=B0=E6=98=8E=EF=BC=8C?= =?UTF-8?q?=E6=88=91=E4=B8=8D=E7=A1=AE=E5=AE=9A=E6=94=B9=E5=AE=8C=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 70 ++++++++++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 38 deletions(-) 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()