From 9371e78703c50ed5b27367a426c6e5bcd588f0a6 Mon Sep 17 00:00:00 2001 From: nyaasuki Date: Mon, 8 Jan 2024 18:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=90=AF=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E9=97=B4,=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 0efd296..8ba1bcc 100644 --- a/main.py +++ b/main.py @@ -19,15 +19,22 @@ def network_restart(): return False return True +def convert_seconds(seconds): + hours = seconds // 3600 + minutes = (seconds % 3600) // 60 + seconds = (seconds % 3600) % 60 + return hours, minutes, seconds + def ascii_tag(): - sys_s = None - sta_s = None + sys_s ,sta_s= None, None if i > 0: sys_s = "Down" - sta_s = "{} network 403 , down".format(time.ctime()) + sta_s = f"{time.ctime()} network 403 , down" else: sys_s = "Up" - sta_s = "{} network 200 , ok".format(time.ctime()) + sta_s = f"{time.ctime()} network 200 , ok" + t = int(time.time() - k) + t = convert_seconds(t) os.system("clear") print(" _ _ _______ ") print(" / \ / |_ |_ __ \ ") @@ -36,13 +43,13 @@ def ascii_tag(): print(" _/ / \ \_ | \_/ |,| |,| \__. |_| | \ \_| \__., ") print("|____| |____|'.__.'_/\__/ '.__.'|____| |___|'.__.' ") print("") - print("系统架构:{}\n异常次数:{}\n当前状态:{}\n最近记录:{}".format(os.name,j,sys_s,sta_s)) + print(f"系统架构:{os.name}\n异常次数:{j}\n当前状态:{sys_s}\n运行时间:{t[0]}时{t[1]}分{t[2]}秒\n最近记录:{sta_s}") return True def main(): - global i ,j - i = 0 - j = 0 + global i, j, k + i, j = 0, 0 + k = time.time() while(1): if not network_test(): #网络异常 i +=1 #异常计数 3次失败重启