mirror-checker/debian.py

32 lines
1016 B
Python

"""
Contains Debian class
"""
from datetime import datetime, timedelta
import requests
from distro import Distro
from shared import CSC_MIRROR
class Debian(Distro):
"""Debian class"""
@staticmethod
def __get_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")
@staticmethod
def name():
"""Get name of Debian"""
return "Debian"
@staticmethod
def check():
"""Check if Debian packages are up-to-date"""
official_dt = Debian.__get_dt("https://ftp-master.debian.org/debian/project/trace/master")
csc_dt = Debian.__get_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
return official_dt < csc_dt + timedelta(hours = 7)