# -*- coding: utf-8 -*-
import io, sys, os, json, ssl, urllib.request, re, html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
todo=json.load(open("todo_upgrade.json",encoding="utf-8"))
items=todo["list"] if isinstance(todo,dict) else todo
targets=["notre-interdisciplinary-mathematics-msim","jhu-cefa6e1","jhu-c1d5ed0","up-cf3f4bd"]
# 找 UPenn Math MA
for x in items:
    det=x.get("det","") or ""
    if x.get("s")=="up" and "mathematics" in det.lower() and x.get("deg")=="MA":
        print("UP MATH MA:",x.get("deg"),det.split("/")[-1],"|",x.get("url",""))
print("---")
results={}
for x in items:
    det=x.get("det","") or ""
    base=det.split("/")[-1]
    if not any(t in base for t in targets): continue
    u=x.get("url","")
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,timeout=10,context=ctx)
        b=r.read(); txt=html.unescape(re.sub(r"<[^>]+>"," ",b.decode("utf-8","ignore")))
        txt=re.sub(r"\s+"," ",txt)
        results[base]={"status":r.status,"bytes":len(b),"textlen":len(txt)}
        open("_33_"+base,"wb").write(b)
        print(base,r.status,len(b),"textlen",len(txt))
    except Exception as e:
        results[base]={"err":str(e)}
        print(base,"ERR",e)
json.dump(results,open("_probe33b.json","w",encoding="utf-8"),ensure_ascii=False,indent=2)
