# -*- coding: utf-8 -*-
import io, sys, os, json, urllib.request, ssl, html, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
todo={os.path.basename(t["det"]):t for t in json.load(open("todo_upgrade.json",encoding="utf-8")) if t["s"]=="usc"}
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
for c in ["ce5bd50","c5b9ed2","c697818","ce04f45","cfaf8d4","c0f389a"]:
    t=todo["usc-"+c+".html"]
    try:
        req=urllib.request.Request(t["url"],headers={"User-Agent":"Mozilla/5.0"})
        b=urllib.request.urlopen(req,timeout=15,context=ctx).read()
        open("_usc7_"+c+".html","wb").write(b)
        txt=html.unescape(re.sub(r"<script.*?</script>","",b.decode("utf-8","ignore"),flags=re.S))
        txt=re.sub(r"<style.*?</style>","",txt,flags=re.S)
        txt=re.sub(r"<[^>]+>"," ",txt); txt=re.sub(r"\s+"," ",txt)
        open("_usc7_"+c+".txt","w",encoding="utf-8").write(txt)
        print(c,len(b),"B txt",len(txt),t["en"][:36])
    except Exception as e:
        print(c,"ERR",type(e).__name__,str(e)[:40])
