import json, re
data = json.load(open('todo_upgrade.json', encoding='utf-8'))
html = open('index_main.html', encoding='utf-8').read()
# 已落库的 en 列表
done_en = set(re.findall(r'en:"([^"]+)"', html))
done_en_lower = {e.lower() for e in done_en}
print('done en count:', len(done_en))

# 已排除项（blocked_notes 历史）
excluded_keywords = [
    'applied economics', 'bioinformatics', 'financial economics', 'geographic information',
    'quantitative financial economics', 'mathematics', 'electrical engineering',
    'biomedical informatics', 'medical physics', 'astronomy and astrophysics',
    'management (phd)', 'management & innovation', 'sustainability management',
    'management and professional accounting', 'economics', 'physics',
    'health policy and management', 'public and nonprofit management',
    'teachers of mathematics', 'transformational teaching', 'entrepreneurship and management'
]

picks = []
seen = set()
for d in data:
    en = d.get('en', '').strip()
    s = d.get('s', '')
    if not en:
        continue
    if en.lower() in done_en_lower:
        continue
    # 跳过已排除
    if any(ex in en.lower() for ex in excluded_keywords):
        continue
    key = (s, en.lower())
    if key in seen:
        continue
    seen.add(key)
    picks.append(d)

# 按学校分组
from collections import defaultdict
by_s = defaultdict(list)
for p in picks:
    by_s[p['s']].append(p)

# 优先：生物/管理/统计/DS/CS/EE/金融/经济/机械/物理/化学/人文管理
priority_schools = ['nyu', 'up', 'col', 'jhu', 'usc', 'umich', 'uchicago', 'berkeley', 'ucla', 'cornell', 'duke', 'northwestern', 'cmu', 'brown', 'emory', 'vanderbilt', 'notre', 'unc', 'uva', 'gatech', 'ucsd', 'wustl', 'geo', 'dartmouth', 'rice', 'princeton', 'harvard', 'yale', 'stanford', 'caltech', 'mit', 'ut', 'ubc', 'mcg', 'uw']

print('=== NYU remaining (生物/管理/统计) ===')
for p in by_s.get('nyu', []):
    en = p.get('en', '')
    if any(k in en.lower() for k in ['biolog', 'skeletal', 'statistic', 'applied stat', 'management', 'public', 'health', 'data', 'analytics', 'information', 'human', 'social']):
        print(' ', en, '|', p.get('deg', ''), '|', p.get('col', ''))

print('=== UPenn remaining ===')
for p in by_s.get('up', []):
    print(' ', p.get('en', ''), '|', p.get('deg', ''), '|', p.get('col', ''))

print('=== UofT remaining ===')
for p in by_s.get('ut', []):
    print(' ', p.get('en', ''), '|', p.get('deg', ''), '|', p.get('col', ''))

print('=== Columbia remaining ===')
for p in by_s.get('col', []):
    print(' ', p.get('en', ''), '|', p.get('deg', ''), '|', p.get('col', ''))

print('=== JHU remaining ===')
for p in by_s.get('jhu', []):
    print(' ', p.get('en', ''), '|', p.get('deg', ''), '|', p.get('col', ''))
