This commit is contained in:
ClF3 2024-01-24 01:38:34 +08:00
parent 0aeb620679
commit df995bf9fe
1 changed files with 16 additions and 16 deletions

32
main.py
View File

@ -51,14 +51,14 @@ def update_graph(filename,history):
def testConnect(url):
try:
time1=datetime.now().timestamp()
code=urllib.request.urlopen(url,timeout=5).getcode()
status_code=urllib.request.urlopen(url,timeout=5).getcode()
time2=datetime.now().timestamp()
delay=int((time2-time1)*1000)
except:
code=404
if code/100>=4:
status_code=404
if status_code/100>=4:
delay=10000
return (code,delay)
return (status_code,delay)
if __name__=="__main__":
lastminute=-1
@ -66,9 +66,9 @@ if __name__=="__main__":
if datetime.now().second==0 and datetime.now().minute!=lastminute:
# if True:
time.sleep(1)
(code,delay)=testConnect("https://blog.clf3.org")
print(code,end=" ")
if code/100<=3:
(status_code,delay)=testConnect("https://blog.clf3.org")
print(status_code,end=" ")
if status_code/100<=3:
print("connected",delay,"ms")
else:
print("error")
@ -83,9 +83,9 @@ if __name__=="__main__":
elif datetime.now().second==10 and datetime.now().minute!=lastminute:
# if True:
time.sleep(1)
(code,delay)=testConnect("https://cloud.clf3.org")
print(code,end=" ")
if code/100<=3:
(status_code,delay)=testConnect("https://cloud.clf3.org")
print(status_code,end=" ")
if status_code/100<=3:
print("connected",delay,"ms")
else:
print("error")
@ -100,9 +100,9 @@ if __name__=="__main__":
elif datetime.now().second==20 and datetime.now().minute!=lastminute:
# if True:
time.sleep(1)
(code,delay)=testConnect("https://code.clf3.org")
print(code,end=" ")
if code/100<=3:
(status_code,delay)=testConnect("https://code.clf3.org")
print(status_code,end=" ")
if status_code/100<=3:
print("connected",delay,"ms")
else:
print("error")
@ -117,9 +117,9 @@ if __name__=="__main__":
elif datetime.now().second==30 and datetime.now().minute!=lastminute:
# if True:
time.sleep(1)
(code,delay)=testConnect("https://git.clf3.org")
print(code,end=" ")
if code/100<=3:
(status_code,delay)=testConnect("https://git.clf3.org")
print(status_code,end=" ")
if status_code/100<=3:
print("connected",delay,"ms")
else:
print("error")