import json, re
from pathlib import Path

root = Path(r"D:\work buddy\2026-11-05-14-15-52")
html = (root / "index_main.html").read_text(encoding="utf-8")

m = re.search(r"const\s+PROGRAMS\s*=\s*\[", html)
start = m.end(); depth = 1; i = start
while i < len(html) and depth > 0:
    c = html[i]
    if c == "[": depth += 1
    elif c == "]": depth -= 1
    i += 1
block = html[start:i-1]

existing_en = set()
existing_url = set()
for mm in re.finditer(r'\{id:"([^"]+)"([\s\S]*?)(?=\{id:"|$)', block):
    body = mm.group(2)
    def grab(k):
        r = re.search(re.escape(k)+r':"([^"]*)"', body)
        return r.group(1) if r else ""
    existing_en.add(grab("en").lower().strip())
    existing_url.add(grab("url"))

todo = json.loads((root / "todo_upgrade.json").read_text(encoding="utf-8"))

# Only MS-level, not PhD
ms_levels = {"MS","MA","MEng","MSc","MScA","MASc","MPH","MPP","MBA","MFA","MSW","MLA","MIM","MSI","MIS","ME","MFA","LAM","MLA","MPS","EdM","SM","MENG","MFA","MSA","MSB","MSM","MSN","MSP","MST","MSX","MATP","MFA","MAcc","MSF","MSBA","MFin","MAM","MSCM","MMS","MSQM","MiM","MSQE","MSFE","MSAcc","MSDS","MSHDS","MSPH","MHS","MFA","MURP","MArch","MLaS","MFS","MPA","MIA","MPM","MUP","MCP","MSOD","MSEM","MESP","MAIA","MIA","MALD","MPP/MPA","MEd","EdM","MFA","MLIS","MIS","MIST","MSLIS","MSLS","PhD/MS","MS/PhD","SM/MEng"}

unverified = []
for t in todo:
    deg = t.get("deg","")
    if "PhD" in deg and "/" not in deg and "MS" not in deg and "MA" not in deg and "MEng" not in deg:
        continue
    en = t.get("en","").lower().strip()
    if en in existing_en:
        continue
    if t.get("det") in existing_url:
        continue
    # exclude known online/executive
    low = en.lower()
    if any(k in low for k in ["online","part-time","executive","distance","hybrid","working professional","mid-career"," evening","weekend"]):
        continue
    unverified.append(t)

print(f"Unverified MS-level candidates: {len(unverified)}")
disc_order = {"cs":0,"ee":1,"fin":2,"econ":3,"ba":4,"ds":5,"stats":6,"me":7,"bio":8,"mgmt":9,"biz":2,"art":50,"hum":50,"socsci":30,"sci":10}
unverified.sort(key=lambda x: (disc_order.get(x.get("disc","zzz"), 60), x.get("s","")))

for t in unverified[:50]:
    print(f"  disc={t.get('disc','?'):6s} s={t.get('s','?'):10s} deg={t.get('deg','?'):10s} en={t.get('en','?')[:75]}")
