# -*- 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")
todo={t["det"].split("/")[-1]:t for t in json.load(open("todo_upgrade.json",encoding="utf-8"))}
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
def fetch(url):
    req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"})
    r=urllib.request.urlopen(req,timeout=15,context=ctx); b=r.read(); return b.decode("utf-8","ignore")
keys=["rice-data-science.html","rice-statistics.html","rice-finance.html","rice-computer-science.html","rice-electrical-computer-engineering.html"]
for key in keys:
    t=todo[key]
    h=fetch(t["url"]); open("_rice10_"+key,"w",encoding="utf-8").write(h)
    txt=re.sub(r"<script.*?</script>","",h,flags=re.S|re.I)
    txt=re.sub(r"<style.*?</style>","",txt,flags=re.S|re.I)
    txt=html.unescape(re.sub(r"<[^>]+>"," ",txt)); txt=re.sub(r"\s+"," ",txt).strip()
    open("_rice10_"+key+".txt","w",encoding="utf-8").write(txt)
    print("====",key,t["en"][:35],"len",len(txt))
