# -*- coding: utf-8 -*-
import io, sys, os, json, urllib.request, ssl, 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
d=json.load(open("todo_upgrade.json",encoding="utf-8"))
rice=[x for x in d if x["s"]=="rice"]
hdr={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"}
for x in rice:
    u=x["url"]
    try:
        req=urllib.request.Request(u,headers=hdr)
        r=urllib.request.urlopen(req,context=ctx,timeout=15)
        b=r.read(); t=b.decode("utf-8","ignore")
        title=re.search(r"<title>(.*?)</title>",t,re.S)
        title=html.unescape(re.sub(r"\s+"," ",title.group(1))).strip()[:60] if title else "?"
        low=t.lower()
        kws=[k for k in ["deadline","application deadline","tuition","toefl","ielts","duolingo","gre","gpa","credits","semester","course"] if k in low]
        print(f"{len(b):6d}B  {x['en'][:38]:38s}  kw={','.join(kws)}  {title}")
    except Exception as e:
        print(f"ERR {type(e).__name__} {str(e)[:40]}  {x['en'][:38]}")
