import json, re
with open('todo_upgrade.json','r',encoding='utf-8') as f:
    todo = json.load(f)
with open('index_main.html','r',encoding='utf-8') as f:
    html = f.read()

existing = re.findall(r'\{id:"[^"]+",s:"([^"]+)",n:"[^"]*",en:"([^"]*)"', html)
existing_set = set((s, en.strip().lower()) for s, en in existing)

remaining = []
for t in todo:
    key = (t['s'], t['en'].strip().lower())
    if key in existing_set:
        continue
    remaining.append(t)

# Excluded items known from history (hard-coded list)
excluded_keywords = [
    'Geographic Information Systems', 'Applied Economics', 'Bioinformatics',
    'Financial Economics', 'Quantitative Financial Economics', 'Medical Physics',
    'Digital Art History', 'Cultural Heritage Management',
    'Aerosol Science', 'Joint MS',
    'Part-time', 'Online', 'Executive', 'Evening',
]

# Filter eng/biz/sci with master's degree
print('=== ENG candidates (master only, first 30) ===')
eng = [t for t in remaining if t.get('disc') == 'eng' and 'PhD' not in t.get('deg','') and 'PhD' not in t.get('en','')]
for i,t in enumerate(eng[:30]):
    skip = any(kw.lower() in t.get('en','').lower() for kw in excluded_keywords)
    mark = ' [SKIP-EXCL]' if skip else ''
    print(i, t['s'], '|', t['en'], '|', t.get('deg',''), '|', t.get('col',''), mark)

print('\n=== BIZ candidates (first 20) ===')
biz = [t for t in remaining if t.get('disc') == 'biz' and 'PhD' not in t.get('deg','')]
for i,t in enumerate(biz[:20]):
    skip = any(kw.lower() in t.get('en','').lower() for kw in excluded_keywords)
    mark = ' [SKIP-EXCL]' if skip else ''
    print(i, t['s'], '|', t['en'], '|', t.get('deg',''), '|', t.get('col',''), mark)

print('\n=== SCI candidates (biology/biostat/stat, first 20) ===')
sci = [t for t in remaining if t.get('disc') == 'sci' and 'PhD' not in t.get('deg','') and any(k in t.get('en','').lower() for k in ['biolog','biostat','stat','data','math','chem','physics','neuroscience','public health','epidemiology'])]
for i,t in enumerate(sci[:20]):
    skip = any(kw.lower() in t.get('en','').lower() for kw in excluded_keywords)
    mark = ' [SKIP-EXCL]' if skip else ''
    print(i, t['s'], '|', t['en'], '|', t.get('deg',''), '|', t.get('col',''), mark)
