forked from public/mirror-checker
Created Debian mirror status checker
This commit is contained in:
parent
8916516973
commit
6379fb4af5
20
main.py
20
main.py
|
@ -7,17 +7,24 @@ This mirror status checker determines whether CSC mirror is up-to-date with upst
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
CSC_MIRROR = "http://mirror.csclub.uwaterloo.ca/"
|
||||||
SUCCESS = "Success: {} up-to-date"
|
SUCCESS = "Success: {} up-to-date"
|
||||||
FAILURE = "Failure: {} out-of-sync"
|
FAILURE = "Failure: {} out-of-sync"
|
||||||
ERROR = "Error: {}\n{}"
|
ERROR = "Error: {}\n{}"
|
||||||
|
|
||||||
|
def get_debian_dt(trace_file_url):
|
||||||
|
"""Get Debian datetime object from trace file"""
|
||||||
|
response_text = requests.get(trace_file_url).text
|
||||||
|
time_str = response_text.split('\n')[0]
|
||||||
|
return datetime.strptime(time_str, "%a %b %d %H:%M:%S UTC %Y")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Arch
|
# Arch
|
||||||
try:
|
try:
|
||||||
arch_json = requests.get("https://archlinux.org/mirrors/status/json/").json()
|
arch_json = requests.get("https://archlinux.org/mirrors/status/json/").json()
|
||||||
last_check_str = arch_json["last_check"]
|
last_check_str = arch_json["last_check"]
|
||||||
last_sync_str = [url for url in arch_json["urls"] if url["url"] == \
|
last_sync_str = [url for url in arch_json["urls"] if url["url"] == \
|
||||||
"http://mirror.csclub.uwaterloo.ca/archlinux/"][0]["last_sync"]
|
f"{CSC_MIRROR}archlinux/"][0]["last_sync"]
|
||||||
last_check_dt = datetime.strptime(last_check_str, "%Y-%m-%dT%H:%M:%S.%fZ")
|
last_check_dt = datetime.strptime(last_check_str, "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
last_sync_dt = datetime.strptime(last_sync_str, "%Y-%m-%dT%H:%M:%SZ")
|
last_sync_dt = datetime.strptime(last_sync_str, "%Y-%m-%dT%H:%M:%SZ")
|
||||||
# According to https://archlinux.org/mirrors/status/:
|
# According to https://archlinux.org/mirrors/status/:
|
||||||
|
@ -26,3 +33,14 @@ if __name__ == "__main__":
|
||||||
print(OUTPUT.format("Arch"))
|
print(OUTPUT.format("Arch"))
|
||||||
except requests.exceptions.RequestException as err:
|
except requests.exceptions.RequestException as err:
|
||||||
print(ERROR.format("Arch", err))
|
print(ERROR.format("Arch", err))
|
||||||
|
|
||||||
|
# Debian
|
||||||
|
try:
|
||||||
|
official_dt = get_debian_dt("https://ftp-master.debian.org/debian/project/trace/master")
|
||||||
|
csc_dt = get_debian_dt(f"{CSC_MIRROR}debian/project/trace/master")
|
||||||
|
# Keep the table cell at https://mirror-master.debian.org/status/mirror-status.html
|
||||||
|
# green and not yellow
|
||||||
|
OUTPUT = SUCCESS if official_dt < csc_dt + timedelta(hours = 7) else FAILURE
|
||||||
|
print(OUTPUT.format("Debian"))
|
||||||
|
except requests.exceptions.RequestException as err:
|
||||||
|
print(ERROR.format("Debian", err))
|
||||||
|
|
Loading…
Reference in New Issue