# -*- coding: utf-8 -*-
import io, sys, os, json, re, ssl, urllib.request, html
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"))
items=todo["list"] if isinstance(todo,dict) else todo
want={
 "notre-data-science-ms---masters-professional.html":"_32_notre-ds.html",
 "notre-aerospace-engineering-msae---masters-traditional.html":"_32_notre-msae.html",
 "notre-civil-and-environmental-engineering-meng---masters-professional.html":"_32_notre-cee-meng.html",
 "notre-civil-engineering-msce---masters-traditional.html":"_32_notre-msce.html",
 "jhu-cd46a5d.html":"_32_jhu-ehe-ms.html",
}
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
for x in items:
    det=os.path.basename(x.get("det",""))
    if det in want:
        u=x["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()
            open(want[det],"wb").write(b)
            txt=html.unescape(re.sub(r"<script[\s\S]*?</script>|<style[\s\S]*?</style>"," ",b.decode("utf-8","ignore")))
            txt=re.sub(r"<[^>]+>"," ",txt); txt=re.sub(r"\s+"," ",txt)
            print("====",det,r.status,len(b),"B text",len(txt))
            print(txt[:1400])
            print()
        except Exception as e:
            print("ERR",det,str(e)[:60])
