#!/usr/bin/env python3
# requirements:
#   * playwright module: pip install playwright       or uv add playwright
#   * Chromium:          playwright install chromium  or uv run playwright install chromium

from playwright.sync_api import sync_playwright

URL = "https://www.githubstatus.com/"

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()

    # wait until JS-rendered content has settled
    page.goto(URL, wait_until="networkidle")

    statuses = {}

    for container in page.query_selector_all("div.component-container"):
        # skip hidden containers
        style = container.get_attribute("style") or ""
        if "display: none" in style:
            continue

        name_el   = container.query_selector("span.name")
        status_el = container.query_selector("span.status-msg")

        if name_el and status_el:
            name   = name_el.inner_text().strip()
            status = status_el.inner_text().strip()
            statuses[name] = status

    browser.close()

print(statuses)
print(statuses.get("Git Operations", "component not found"))
