Files
apo_scripts/check.py
T

72 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
import subprocess
import sys
import yaml
def check_channels(filename):
with open(filename, "r") as f:
config = yaml.safe_load(f)
# Only read actual channel definitions
channels = config["channels"]
online = 0
offline = 0
timeouts = 0
print(f"\nChecking {len(channels)} channels...\n")
for alias, channel in channels.items():
try:
result = subprocess.run(
["bs", "avail", channel],
capture_output=True,
text=True,
timeout=15
)
is_online = channel in [
line.strip() for line in result.stdout.splitlines()
]
status = "ONLINE" if is_online else "OFFLINE"
except subprocess.TimeoutExpired:
status = "TIMEOUT"
is_online = False
except OSError:
status = "ERROR"
if status == "ONLINE":
online += 1
symbol = "✓"
elif status == "OFFLINE":
offline +=1
symbol = "✗"
elif status == "TIMEOUT":
timeouts +=1
symbol = "!"
else:
offline +=1
symbol = "?"
print (f"{symbol} {alias:<18} {status:<8} {channel}")
print(f"\nSummary: {online} online, {offline} offline")
return offline == 0 and timeouts==0
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: check <channels.yaml>")
sys.exit(1)
success = check_channels(sys.argv[1])
sys.exit(0 if success else 1)