Added option of configuration file in standard input

This commit is contained in:
Laura Nguyen 2021-09-03 17:43:34 -04:00
parent d04b65928e
commit 2ff0b0c69b
2 changed files with 35 additions and 1 deletions

26
example.in Normal file
View File

@ -0,0 +1,26 @@
AlmaLinux
Alpine
Apache
Arch
CentOS
Ceph
CPAN
Cygwin
Debian
DebianCD
DebianMultimedia
DebianPorts
DebianSecurity
Eclipse
Fedora
FreeBSD
GentooDistfiles
GentooPortage
GNOME
GNU
Gutenberg
IPFire
KDE
KDEApplicationData
Kernel
OpenBSD

10
main.py
View File

@ -6,6 +6,7 @@ This mirror status checker determines whether CSC mirror is up-to-date with upst
import time
import os
import sys
import requests
from arch import Arch
from ceph import Ceph
@ -106,8 +107,12 @@ if __name__ == "__main__":
with open("data.json", "r", encoding = "utf-8") as file:
data = json.load(file)
if sys.stdin.isatty():
distros = data
else:
distros = [distro.rstrip() for distro in sys.stdin.readlines()]
current_time = int(time.time())
for distro in data:
for distro in distros:
try:
if distro == "CPAN":
res_json = requests.get("http://mirrors.cpan.org/cpan-json.txt").json()
@ -134,6 +139,9 @@ if __name__ == "__main__":
continue
elif distro == "IPFire":
checker_result = ipfire_checker()
elif distro not in data:
print(f"Failure: {distro} does not exist")
continue
else:
checker_result = general_checker(data, distro)
if checker_result: