import json, re

html = open('index_main.html', encoding='utf-8').read()
existing_ids = set(re.findall(r'id:"([^"]+)"', html))
existing_urls = set(re.findall(r'url:"(details/[^"]+)"', html))

todo = json.load(open('todo_upgrade.json', encoding='utf-8'))
pending = [item for item in todo if item.get('det','') not in existing_urls and item.get('url','') not in existing_urls]

# Hot priority: CS/EE/金融/经济/BA/DS/统计/机械/生物/管理
hot_keywords = [
    'computer science', 'data science', 'analytics', 'business analytics',
    'electrical engineering', 'computer engineering', 'finance', 'financial',
    'economics', 'statistic', 'machine learning', 'mechanical engineering',
    'biomedical', 'biology', 'management', 'management of technology',
    'information systems', 'information technology', 'operations research',
    'industrial engineering', 'systems engineering', 'quantitative',
    'accounting', 'marketing', 'entrepreneurship',
]

# Filter hot direction pending
hot_pending = []
for p in pending:
    en_lower = p.get('en', '').lower()
    disc = p.get('disc', '').lower()
    deg = p.get('deg', '')
    
    # Skip clearly excluded
    if any(x in en_lower for x in ['event management', 'hospitality', 'human capital', 'project management', 'travel and tourism', 'sports management', 'real estate', 'global hospitality', 'sustainability management', 'translation', 'creative writing', 'teaching', 'education', 'art history', 'religion', 'music', 'theater', 'dance', 'film', 'cinema', 'journalism', 'communication', 'english', 'history', 'philosophy', 'sociology', 'political science', 'international relations', 'public policy', 'social work', 'divinity', 'theology', 'law', 'public health']):
        continue
    
    # Check hot keywords
    if any(kw in en_lower or kw in disc for kw in hot_keywords):
        hot_pending.append(p)

print(f"Hot pending count: {len(hot_pending)}")
print("\n--- Hot pending by school ---")
from collections import Counter
school_counts = Counter(p.get('s', '?') for p in hot_pending)
for s, c in school_counts.most_common(20):
    print(f"  {s}: {c}")

print("\n--- First 30 hot pending ---")
for i, p in enumerate(hot_pending[:30]):
    print(f"{i+1}. [{p.get('s','?')}] {p.get('en','?')} | {p.get('deg','?')} | disc={p.get('disc','?')} | det={p.get('det','')}")
