# -*- coding: utf-8 -*-
import re, io, sys, os, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
h = open('index_main.html', encoding='utf-8').read()
mp = re.search(r'const PROGRAMS\s*=\s*\[(.*?)\];', h, re.S)
recs = re.findall(r'\{id:"([^"]+)"([\s\S]*?)(?=\{id:"|$)', mp.group(1))
by = {r[0]: r[1] for r in recs}
ids = ["mcg-ece-phd","uw-ece-phd","nu-ece-phd","rice-ece-phd","vanderbilt-ece-phd",
       "wustl-ee-phd","notre-ee-phd","ucsd-cse-bioinfo-phd"]
for i in ids:
    if i not in by:
        print(i, "*** NOT IN PROGRAMS ***"); continue
    b = by[i]
    def g(k):
        m = re.search(k+r':"([^"]*)"', b); return m.group(1) if m else "<none>"
    print("="*70)
    print(i)
    print("  s:", g('s'), "| lvl:", re.search(r'lvl:"([^"]*)"',b).group(1) if re.search(r'lvl:"([^"]*)"',b) else "?",
          "| deg:", g('deg'))
    print("  n:", g('n'))
    print("  en:", g('en'))
    print("  url:", g('url'), "| disk:", os.path.exists(g('url')))
# CATD 中文名核对
catd = re.search(r'const CATD\s*=\s*\[(.*?)\];', h, re.S).group(1)
print("\n=== CATD 对应行 ===")
for i in ids:
    url = re.search(r'url:"([^"]*)"', by[i]).group(1) if i in by else ""
    for row in re.findall(r'\["([^"]*)"[^]]*\]', catd):
        if url and url in row:
            cells = re.findall(r'"([^"]*)"', row)
            print(i, "| CATD n:", cells[3] if len(cells)>3 else "?", "| deg:", cells[4] if len(cells)>4 else "?")
            break
