# -*- 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"]:t for t in json.load(open("todo_upgrade.json",encoding="utf-8")) if t["s"]=="usc"}
pick={
 "c8eee33":"mms","c815a5c":"mppds","c1629a1":"ippam","c01aa3b":"mielr","cb637af":"mnlm"
}
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
for short,tag in pick.items():
    det="details/usc-"+short+".html"; t=todo[det]; u=t["url"]
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"})
        b=urllib.request.urlopen(req,timeout=15,context=ctx).read()
        open(f"_usc6_{tag}.html","wb").write(b)
        txt=html.unescape(re.sub(r"<script.*?</script>"," ",b.decode("utf-8","ignore"),flags=re.S|re.I))
        txt=re.sub(r"<style.*?</style>"," ",txt,flags=re.S|re.I)
        txt=re.sub(r"<[^>]+>"," ",txt); txt=re.sub(r"\s+"," ",txt).strip()
        open(f"_usc6_{tag}.txt","w",encoding="utf-8").write(txt)
        print(tag,len(b),"B",len(txt),"txt",u)
    except Exception as e:
        print(tag,"ERR",type(e).__name__,str(e)[:50])
