mirror-checker/arch.py

29 lines
1.0 KiB
Python

"""
Contains Arch class
"""
from datetime import datetime, timedelta
import requests
from distro import Distro
from shared import CSC_MIRROR
class Arch(Distro):
"""Arch class"""
@staticmethod
def name():
"""Get name of Arch"""
return "Arch"
@staticmethod
def check():
"""Check if Arch packages are up-to-date"""
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"] == \
f"{CSC_MIRROR}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
return last_check_dt < last_sync_dt + timedelta(hours = 1)