import re
with open('index_main.html','r',encoding='utf-8') as f:
    html = f.read()
# extract all {id, en, s} from PROGRAMS
block = re.search(r'const PROGRAMS=(\[[\s\S]*?\]);', html)
if not block:
    print('no PROGRAMS block')
    raise SystemExit
body = block.group(1)
# each entry: {id:"...",s:"...",...,en:"...",...}
entries = re.findall(r'\{id:"([^"]+)"([\s\S]*?)(?=\{id:"|,?\n\];)', body)
print('total entries:', len(entries))
# look for specific keywords
keys = ['MIT','DED','UCSD','Advanced Manufacturing','Yale','Statistic','Bioinformatics','Harvard Business','ECE','EECS','UNC','STANDS','Spatial Economics','Public Health Data Science','Viterbi','Computer Science']
for i, (eid, rest) in enumerate(entries):
    m_en = re.search(r'en:"([^"]+)"', rest)
    m_s = re.search(r's:"([^"]+)"', rest)
    en = m_en.group(1) if m_en else ''
    s = m_s.group(1) if m_s else ''
    for k in keys:
        if k.lower() in en.lower():
            print(f'{i:4d} | {eid:40s} | {s:10s} | {en}')
            break
