import re, os, json, sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
base = os.path.dirname(os.path.abspath(__file__))
r = open(os.path.join(base, "index_main.html"), encoding="utf-8").read()
seg = re.search(r'const PROGRAMS\s*=\s*\[(.*?)\];', r, re.S).group(1)
blocks = re.findall(r'\{id:"([^"]+)"([\s\S]*?)(?=\{id:"|$)', seg)
want = ["notre-cse-mscse","notre-ee-msee","notre-ms-acms",
        "jhu-finecon","jhu-bioinfo-ms","jhu-gis-ms",
        "usc-aeec-ms","usc-stats-ms","usc-seda-ms","usc-apmath-ms",
        "illinois-mspe","ubc-mppga","ut-mmpa","ut-mmi",
        "cmu-le-ms","gatech-msbcfm"]
for bid, body in blocks:
    if bid in want:
        n = re.search(r'n:"([^"]*)"', body)
        en = re.search(r'en:"([^"]*)"', body)
        deg = re.search(r'deg:"([^"]*)"', body)
        url = re.search(r'url:"([^"]*)"', body)
        tui = re.search(r'tui:"([^"]*)"', body)
        print(f"[{bid}]")
        print(f"  n={n.group(1) if n else '?'} | deg={deg.group(1) if deg else '?'}")
        print(f"  en={en.group(1) if en else '?'}")
        print(f"  url={url.group(1) if url else '?'}")
        print(f"  tui={tui.group(1) if tui else '?'}")
