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次失败重启