From cb8b9d0b2dfd933e00a94636018ca1323542ce7f Mon Sep 17 00:00:00 2001 From: Laura Nguyen Date: Mon, 16 Aug 2021 18:23:04 -0400 Subject: [PATCH] Created Arch mirror status checker --- main.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..219f98f --- /dev/null +++ b/main.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +""" +This mirror status checker determines whether CSC mirror is up-to-date with upstream +""" + +from datetime import datetime, timedelta +import requests + +SUCCESS = "Success: {} up-to-date" +FAILURE = "Failure: {} out-of-sync" +ERROR = "Error: {}\n{}" + +if __name__ == "__main__": + # Arch + try: + arch_json = requests.get("https://archlinux.org/mirrors/status/json/").json() + last_check_str = arch_json["last_check"] + last_sync_str = [url for url in arch_json["urls"] if url["url"] == \ + "http://mirror.csclub.uwaterloo.ca/archlinux/"][0]["last_sync"] + 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") + # According to https://archlinux.org/mirrors/status/: + # Due to the timing of mirror checks, any value under one hour should be viewed as ideal + OUTPUT = SUCCESS if last_check_dt < last_sync_dt + timedelta(hours = 1) else FAILURE + print(OUTPUT.format("Arch")) + except requests.exceptions.RequestException as err: + print(ERROR.format("Arch", err))