# -*- coding: utf-8 -*-
import io, sys, os, 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
def get(url):
    req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0"})
    r=urllib.request.urlopen(req,timeout=15,context=ctx); b=r.read()
    t=b.decode("utf-8","ignore"); t=re.sub(r'<script[\s\S]*?</script>',' ',t); t=re.sub(r'<style[\s\S]*?</style>',' ',t)
    t=re.sub(r'<[^>]+>',' ',t); t=html.unescape(t); return re.sub(r'\s+',' ',t)
for tag,url in [("amreq","https://dornsife.usc.edu/mathematics/degree-requirements/"),("amadm","https://dornsife.usc.edu/mathematics/admissions/")]:
    try:
        t=get(url); open(f"_usc5_{tag}.txt","w",encoding="utf-8").write(t); print("="*20,tag,len(t))
        for k in ["Master","unit","credit","degree","deadline","TOEFL","IELTS","GRE","prerequisite","Applied","Analysis","Statistics","probability"]:
            i=t.lower().find(k.lower())
            if i>=0: print(f"[{k}] …{t[max(0,i-40):i+120]}…")
    except Exception as e:
        print(tag,"ERR",type(e).__name__,str(e)[:50])
print("="*20,"annadm")
t=open("_usc5_annadm.txt",encoding="utf-8").read()
for k in ["deadline","TOEFL","IELTS","GPA","recommend","GRE","application","unit","credit","tuition","English"]:
    i=t.lower().find(k.lower())
    if i>=0: print(f"[{k}] …{t[max(0,i-40):i+120]}…")
