import re, sys
sys.stdout.reconfigure(encoding='utf-8')

with open('index_main.html','r',encoding='utf-8') as f:
    html = f.read()

# 提取所有 PROGRAMS 条目的 en 字段
entries = []
for m in re.finditer(r'\{id:"([^"]+)"(.*?)\}(?=\{id:"|\n\];)', html):
    block = m.group(0)
    id_m = re.search(r'id:"([^"]+)"', block)
    en_m = re.search(r'en:"([^"]*)"', block)
    s_m = re.search(r's:"([^"]*)"', block)
    n_m = re.search(r'n:"([^"]*)"', block)
    if id_m:
        entries.append({
            'id': id_m.group(1),
            's': s_m.group(1) if s_m else '',
            'en': en_m.group(1) if en_m else '',
            'n': n_m.group(1) if n_m else ''
        })

# 检查候选
candidates = [
    ('ucsd', 'Computational Science, Mathematics, and Engineering'),
    ('ucsd', 'Computational Social Science'),
    ('ucsd', 'Data Science and Engineering'),
    ('unc', 'Applied Data Science'),
    ('unc', 'Statistics, Analytics, and Data Science'),
    ('jhu', 'Geographic Information Systems'),
    ('dartmouth', 'Medical Informatics'),
    ('notre', 'Applied and Computational Mathematics and Statistics'),
    ('emory', 'Computer Science'),
    ('emory', 'Data Science'),
    ('berkeley', 'Biostatistics'),
    ('berkeley', 'Information Management and Systems'),
    ('usc', 'Public Health Data Science'),
    ('usc', 'Applied Biostatistics and Epidemiology'),
    ('uw', 'Health Informatics and Analytics'),
    ('wustl', 'Statistics and Data Science'),
]

for school, en_name in candidates:
    matches = [e for e in entries if e['s']==school and (en_name.lower() in e['en'].lower() or e['en'].lower() in en_name.lower())]
    if matches:
        print(f"[EXISTS] {school} - {en_name}")
        for m in matches:
            print(f"    -> id={m['id']}, en={m['en']}, n={m['n']}")
    else:
        print(f"[NEW] {school} - {en_name}")
