Store data in JSON file
This commit is contained in:
parent
8c305397b9
commit
1cbb02b3fa
|
@ -0,0 +1,51 @@
|
||||||
|
{
|
||||||
|
"Arch": {
|
||||||
|
"out_of_date_since": null,
|
||||||
|
"out_of_date_interval": 86400,
|
||||||
|
"csc": "archlinux/",
|
||||||
|
"upstream": "http://arch.mirror.constant.com/",
|
||||||
|
"file": "lastupdate"
|
||||||
|
},
|
||||||
|
"Ceph": {
|
||||||
|
"out_of_date_since": null,
|
||||||
|
"out_of_date_interval": 86400,
|
||||||
|
"csc": "ceph/",
|
||||||
|
"upstream": "https://download.ceph.com/",
|
||||||
|
"file": "timestamp"
|
||||||
|
},
|
||||||
|
"Debian": {
|
||||||
|
"out_of_date_since": null,
|
||||||
|
"out_of_date_interval": 86400,
|
||||||
|
"csc": "",
|
||||||
|
"upstream": "https://ftp-master.debian.org/",
|
||||||
|
"file": "debian/project/trace/master"
|
||||||
|
},
|
||||||
|
"Eclipse": {
|
||||||
|
"out_of_date_since": null,
|
||||||
|
"out_of_date_interval": 172800,
|
||||||
|
"csc": "eclipse/",
|
||||||
|
"upstream": "http://download.eclipse.org/",
|
||||||
|
"file": "TIME"
|
||||||
|
},
|
||||||
|
"GNU": {
|
||||||
|
"out_of_date_since": null,
|
||||||
|
"out_of_date_interval": 86400,
|
||||||
|
"csc": "",
|
||||||
|
"upstream": "https://mirrors.kernel.org/",
|
||||||
|
"file": "gnu/mirror-updated-timestamp.txt"
|
||||||
|
},
|
||||||
|
"Kernel": {
|
||||||
|
"out_of_date_since": null,
|
||||||
|
"out_of_date_interval": 86400,
|
||||||
|
"csc": "kernel.org/",
|
||||||
|
"upstream": "https://mirrors.edge.kernel.org/pub/",
|
||||||
|
"file": "linux/kernel/next/sha256sums.asc"
|
||||||
|
},
|
||||||
|
"OpenBSD": {
|
||||||
|
"out_of_date_since": null,
|
||||||
|
"out_of_date_interval": 86400,
|
||||||
|
"csc": "",
|
||||||
|
"upstream": "https://ftp.openbsd.org/pub/",
|
||||||
|
"file": "OpenBSD/timestamp"
|
||||||
|
}
|
||||||
|
}
|
27
main.py
27
main.py
|
@ -4,6 +4,7 @@
|
||||||
This mirror status checker determines whether CSC mirror is up-to-date with upstream
|
This mirror status checker determines whether CSC mirror is up-to-date with upstream
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
import requests
|
import requests
|
||||||
from arch import Arch
|
from arch import Arch
|
||||||
from ceph import Ceph
|
from ceph import Ceph
|
||||||
|
@ -52,10 +53,32 @@ if __name__ == "__main__":
|
||||||
except requests.exceptions.RequestException as err:
|
except requests.exceptions.RequestException as err:
|
||||||
print(f"Error: {distro.name()}\n{err}")"""
|
print(f"Error: {distro.name()}\n{err}")"""
|
||||||
|
|
||||||
distros = json.load(open('distros.json',))
|
"""distros = json.load(open('distros.json',))
|
||||||
print(distros)
|
print(distros)
|
||||||
|
|
||||||
for distro in distros:
|
for distro in distros:
|
||||||
print(distro[0] + ":")
|
print(distro[0] + ":")
|
||||||
print("CSC mirror: " + checker(distro[1], distro[3]))
|
print("CSC mirror: " + checker(distro[1], distro[3]))
|
||||||
print("Official distro: " + checker(distro[2], distro[3]))
|
print("Official distro: " + checker(distro[2], distro[3]))"""
|
||||||
|
|
||||||
|
with open("data.json", "r", encoding = "utf-8") as file:
|
||||||
|
data = json.load(file)
|
||||||
|
current_time = int(time.time())
|
||||||
|
for distro in data:
|
||||||
|
csc_url = "http://mirror.csclub.uwaterloo.ca/" + data[distro]["csc"] \
|
||||||
|
+ data[distro]["file"]
|
||||||
|
upstream_url = data[distro]["upstream"] + data[distro]["file"]
|
||||||
|
try:
|
||||||
|
if requests.get(csc_url).text == requests.get(upstream_url).text:
|
||||||
|
data[distro]["out_of_date_since"] = None
|
||||||
|
elif data[distro]["out_of_date_since"] is None:
|
||||||
|
data[distro]["out_of_date_since"] = current_time
|
||||||
|
elif current_time - data[distro]["out_of_date_since"] \
|
||||||
|
> data[distro]["out_of_date_interval"]:
|
||||||
|
print(f"Failure: {distro} out-of-sync")
|
||||||
|
continue
|
||||||
|
print(f"Success: {distro} up-to-date")
|
||||||
|
except requests.exceptions.RequestException as err:
|
||||||
|
print(f"Error: {distro}\n{err}")
|
||||||
|
with open("data.json", "w", encoding = "utf-8") as file:
|
||||||
|
json.dump(data, file, indent = 4)
|
||||||
|
|
Loading…
Reference in New Issue