# -*- coding: utf-8 -*-
import json, sys, io, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
todo = json.load(open("todo_upgrade.json", encoding="utf-8"))
idx = open("index_main.html", encoding="utf-8").read()
existing_dets = set(re.findall(r'url:"(details/[^"]+)"', idx))
# MS only, non-PhD, hot disc
ms = [t for t in todo if t.get("deg","").startswith("MS") and t.get("det") not in existing_dets]
# group by school
from collections import defaultdict
by = defaultdict(list)
for t in ms: by[t["s"]].append(t)
for s, items in sorted(by.items(), key=lambda x:-len(x[1]))[:12]:
    print(f"=== {s}: {len(items)} MS pending ===")
    for it in items[:10]:
        print(" ", it["disc"], it["en"], "|", it["det"])
