# -*- coding: utf-8 -*-
import io, sys, os, re, json, urllib.request, ssl, socket
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
todo=json.load(open("todo_upgrade.json",encoding="utf-8"))
watch={"nyu","unc","uva","emory","ucla","berkeley","ucsd","yale","gatech","up","duke","jhu"}
def is_phd(deg): return re.search(r"phd|drph|doctoral|scd",deg,re.I)
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
socket.setdefaulttimeout(8)
hdr={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120 Safari/537.36"}
out=[]
for it in todo:
    if it["s"] not in watch or is_phd(it.get("deg","")): continue
    url=it.get("url","")
    if not url.startswith("http"): continue
    try:
        req=urllib.request.Request(url,headers=hdr)
        r=urllib.request.urlopen(req,context=ctx)
        b=r.read(); out.append((it["s"],it["deg"],it["en"][:40],r.status,len(b),url))
    except urllib.error.HTTPError as e:
        out.append((it["s"],it["deg"],it["en"][:40],e.code,0,url))
    except Exception as e:
        out.append((it["s"],it["deg"],it["en"][:40],"ERR",str(e)[:30],url))
for r in sorted(out,key=lambda x:(x[0],str(x[3]))):
    print(f"{r[0]:9} {str(r[3]):5} {r[4]:6} {r[1]:10} {r[2]}")
