import re, os, 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)
groups = {}
for bid, body in blocks:
    en = re.search(r'en:"([^"]*)"', body)
    en = en.group(1) if en else ""
    key = (bid.split("-")[0], en.lower().strip())
    groups.setdefault(key, []).append((bid, body))

pairs = [
 ("cornell-aem-mps","cornell-mps-aem"),
 ("princeton-fin-mfin","princeton-mfin"),
 ("ucsd-bioe-med-ms","ucsd-bioe-ms-med"),
 ("umich-ece-ms","umich-ms-ece"),
 ("umich-me-mse","umich-mse-me"),
]
byid = {bid:body for bid,body in blocks}
for a,b in pairs:
    print(f"===== {a}  vs  {b} =====")
    for x in (a,b):
        body=byid.get(x)
        if not body: print(f"  {x} 不在库"); continue
        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); ddl=re.search(r'ddl:"([^"]*)"',body)
        lang=re.search(r'lang:"([^"]*)"',body); test=re.search(r'cls:"([^"]*)"',body)
        print(f"  [{x}] n={n.group(1) if n else '?'}")
        print(f"     en={en.group(1) if en else '?'} | deg={deg.group(1) if deg else '?'} | url={url.group(1) if url else '?'}")
        print(f"     ddl={ddl.group(1) if ddl else '-'} | lang={lang.group(1) if lang else '-'} | test={test.group(1) if test else '-'} | tui={tui.group(1) if tui else '-'}")
    print()
