mirror-checker/projects/ubuntu.py

29 lines
980 B
Python

"""
Contains ubuntu class
"""
import os
from distro import Distro
from shared import CSC_MIRROR
import requests
import datefinder # another date finding library
class ubuntu(Distro):
"""ubuntu class"""
@staticmethod
def check(data, distro, current_time):
page = requests.get(data[distro]["upstream"]).text
indexOfFile = page.find("last verified on")
# segment_clean = re.sub(r'\s\d+\s', ' ', page[indexOfFile:]) # removes numbers for size
# segment_clean = re.sub(r'\s\d+\w*\s', ' ', page[indexOfFile:]) # removes numbers + size unit. e.x. 50kb
matches = list(datefinder.find_dates(page[indexOfFile:]))
# print(matches)
if len(matches) > 0:
date = matches[0] # date is of type datetime.datetime
return(current_time - date.strftime("%Y/%m/%d, %H:%M:%S"))
else:
return(False)
# https://launchpad.net/ubuntu/+mirror/mirror.csclub.uwaterloo.ca-archive