diff --git a/main.py b/main.py index be17c44..0c7bbfe 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import numpy as np import urllib.request from datetime import datetime import time +import os recent_blog=[] recent_cloud=[] recent_code=[] @@ -19,6 +20,7 @@ yellow=(0x00,0xcc,0xff) light_green=(0x33,0xff,0xcc) green=(0x00,0xcc,0x00) imgpath="/tmp/uptime-graph/" + def update_history(history,recent): average=0 for i in recent: @@ -61,10 +63,11 @@ def testConnect(url): return (status_code,delay) if __name__=="__main__": - lastminute=-1 + if not os.path.exists(imgpath):#如果路径不存在 + os.makedirs(imgpath) while True: - if datetime.now().second==0 and datetime.now().minute!=lastminute: - # if True: + time.sleep(0.5) + if datetime.now().second==0: time.sleep(1) (status_code,delay)=testConnect("https://blog.clf3.org") print(status_code,end=" ") @@ -80,8 +83,7 @@ if __name__=="__main__": recent_blog=[] recent_blog.append(delay) - elif datetime.now().second==10 and datetime.now().minute!=lastminute: - # if True: + elif datetime.now().second==10: time.sleep(1) (status_code,delay)=testConnect("https://cloud.clf3.org") print(status_code,end=" ") @@ -97,7 +99,7 @@ if __name__=="__main__": recent_cloud=[] recent_cloud.append(delay) - elif datetime.now().second==20 and datetime.now().minute!=lastminute: + elif datetime.now().second==20: # if True: time.sleep(1) (status_code,delay)=testConnect("https://code.clf3.org") @@ -114,7 +116,7 @@ if __name__=="__main__": recent_code=[] recent_code.append(delay) - elif datetime.now().second==30 and datetime.now().minute!=lastminute: + elif datetime.now().second==30: # if True: time.sleep(1) (status_code,delay)=testConnect("https://git.clf3.org")