"""重新扫描：排除 Stanford（已知 403），挑其他热门学校半核验页"""
import re, json

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

m = re.search(r'const PROGRAMS=(\[[\s\S]*?\]);', html)
prog_str = m.group(1)
entries = re.findall(r'\{id:"([^"]+)"([\s\S]*?)(?=\{id:"|,?\n\];)', prog_str)

# 排除已知 403 的学校
blocked_schools = {'stanford', 'uchicago'}  # uchicago-ssl 也在 blocked_notes

half = []
for pid, body in entries:
    s_m = re.search(r's:"([^"]*)"', body)
    n_m = re.search(r'n:"([^"]*)"', body)
    deg_m = re.search(r'deg:"([^"]*)"', body)
    ddl_m = re.search(r'ddl:"([^"]*)"', body)
    tui_m = re.search(r'tui:"([^"]*)"', body)
    url_m = re.search(r'url:"([^"]*)"', body)
    test_m = re.search(r'test:\{cls:"([^"]*)"', body)
    s = s_m.group(1) if s_m else ''
    n = n_m.group(1) if n_m else ''
    deg = deg_m.group(1) if deg_m else ''
    ddl = ddl_m.group(1) if ddl_m else ''
    tui = tui_m.group(1) if tui_m else ''
    url = url_m.group(1) if url_m else ''
    test = test_m.group(1) if test_m else ''
    
    if s in blocked_schools: continue
    
    missing = []
    if not ddl or '待补' in ddl: missing.append('ddl')
    if not tui or '待补' in tui: missing.append('tui')
    if not test or '待补' in test or '?' in test: missing.append('test')
    
    if missing:
        half.append({
            'id': pid, 's': s, 'n': n, 'deg': deg,
            'ddl': ddl, 'tui': tui, 'test': test, 'url': url,
            'missing': missing
        })

# 热门学校（CS/EE/金融/经济/BA/DS/统计）
hot = ['cmu', 'gatech', 'illinois', 'umich', 'usc', 'nyu', 'col', 'up', 'cornell', 'berkeley', 'ucla', 'mit', 'princeton', 'jhu', 'wustl', 'duke', 'northwestern']
def score(item):
    s = 0
    if item['s'] in hot:
        s -= hot.index(item['s']) + 1
    s -= len(item['missing']) * 10
    return s
half.sort(key=score)

print(f"排除 Stanford/uchicago 后半核验: {len(half)}")
print("\n=== 候选前 25 ===")
for i, h in enumerate(half[:25]):
    print(f"{i+1}. [{h['s']}] {h['id']} | {h['n'][:30]} | {h['deg']} | 缺: {h['missing']}")
