forked from public/mirror-checker
Created CPAN mirror status checker
This commit is contained in:
parent
0ef22b660a
commit
273200abdf
|
@ -41,6 +41,9 @@
|
||||||
"upstream": "https://download.ceph.com/",
|
"upstream": "https://download.ceph.com/",
|
||||||
"file": "timestamp"
|
"file": "timestamp"
|
||||||
},
|
},
|
||||||
|
"CPAN": {
|
||||||
|
"out_of_date_interval": 172800
|
||||||
|
},
|
||||||
"Cygwin": {
|
"Cygwin": {
|
||||||
"out_of_date_since": null,
|
"out_of_date_since": null,
|
||||||
"out_of_date_interval": 86400,
|
"out_of_date_interval": 86400,
|
||||||
|
|
16
main.py
16
main.py
|
@ -20,6 +20,8 @@ import json # import json to read distro info stored in json file
|
||||||
|
|
||||||
import datefinder # another date finding library
|
import datefinder # another date finding library
|
||||||
|
|
||||||
|
CSC_MIRROR = "http://mirror.csclub.uwaterloo.ca/"
|
||||||
|
|
||||||
def checker(directory_URL, file_name):
|
def checker(directory_URL, file_name):
|
||||||
page = requests.get(directory_URL).text
|
page = requests.get(directory_URL).text
|
||||||
indexOfFile = page.find(file_name)
|
indexOfFile = page.find(file_name)
|
||||||
|
@ -53,8 +55,7 @@ def ipfire_checker():
|
||||||
|
|
||||||
def general_checker(data_json, distro_name):
|
def general_checker(data_json, distro_name):
|
||||||
"""General distro checker"""
|
"""General distro checker"""
|
||||||
csc_url = "http://mirror.csclub.uwaterloo.ca/" + data_json[distro_name]["csc"] \
|
csc_url = CSC_MIRROR + data_json[distro_name]["csc"] + data_json[distro_name]["file"]
|
||||||
+ data_json[distro_name]["file"]
|
|
||||||
upstream_url = data_json[distro_name]["upstream"] + data_json[distro_name]["file"]
|
upstream_url = data_json[distro_name]["upstream"] + data_json[distro_name]["file"]
|
||||||
return requests.get(csc_url).text == requests.get(upstream_url).text
|
return requests.get(csc_url).text == requests.get(upstream_url).text
|
||||||
|
|
||||||
|
@ -78,6 +79,17 @@ if __name__ == "__main__":
|
||||||
current_time = int(time.time())
|
current_time = int(time.time())
|
||||||
for distro in data:
|
for distro in data:
|
||||||
try:
|
try:
|
||||||
|
if distro == "CPAN":
|
||||||
|
res_json = requests.get("http://mirrors.cpan.org/cpan-json.txt").json()
|
||||||
|
for mirror in res_json:
|
||||||
|
if mirror["url"] == f"{CSC_MIRROR}CPAN/":
|
||||||
|
if current_time - int(mirror["age"]) \
|
||||||
|
> data[distro]["out_of_date_interval"]:
|
||||||
|
print(f"Failure: {distro} out-of-sync")
|
||||||
|
else:
|
||||||
|
print(f"Success: {distro} up-to-date")
|
||||||
|
break
|
||||||
|
continue
|
||||||
if distro == "IPFire":
|
if distro == "IPFire":
|
||||||
checker_result = ipfire_checker()
|
checker_result = ipfire_checker()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue