📄 fetch_dashboard.py 1,730 bytes Apr 19, 2026 📋 Raw

!/usr/bin/env python3

"""
Fetch and display TIDY-CRE dashboard information.
Usage: fetch_dashboard.py [host] [port] [timeout]
"""

import sys
import urllib.request
import urllib.error
import json

def fetch_dashboard(host: str, port: int, timeout: float):
"""Fetch the dashboard HTML and extract key info."""
url = f"http://{host}:{port}/"

try:
    req = urllib.request.Request(url, method='GET')
    with urllib.request.urlopen(req, timeout=timeout) as response:
        html = response.read().decode('utf-8')

        print(f"[OK] Dashboard fetched from {url}")
        print(f"  - Status: {response.status}")
        print(f"  - Content-Type: {response.headers.get('Content-Type', 'unknown')}")
        print(f"  - Content-Length: {len(html)} bytes")

        # Try to extract title
        import re
        title_match = re.search(r'<title>(.*?)</title>', html, re.IGNORECASE)
        if title_match:
            print(f"  - Page Title: {title_match.group(1)}")

        return True
except urllib.error.HTTPError as e:
    print(f"[FAIL] HTTP Error {e.code}: {e.reason}")
    return False
except urllib.error.URLError as e:
    print(f"[FAIL] URL Error: {e.reason}")
    return False
except Exception as e:
    print(f"[FAIL] Error: {e}")
    return False

def main():
host = sys.argv[1] if len(sys.argv) > 1 else "127.0.0.1"
port = int(sys.argv[2]) if len(sys.argv) > 2 else 18789
timeout = float(sys.argv[3]) if len(sys.argv) > 3 else 5.0

result = fetch_dashboard(host, port, timeout)
sys.exit(0 if result else 1)

if name == "main":
main()