# -*- 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
urls={
 "DS系站":"https://datascience.rice.edu",
 "CS系站":"https://www.cs.rice.edu",
 "Stat系站":"https://stat.rice.edu",
 "ECE系站":"https://ece.rice.edu",
 "Business":"https://business.rice.edu",
 "GradAdm":"https://ga.rice.edu",
}
for k,u in urls.items():
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"})
        r=urllib.request.urlopen(req,timeout=12,context=ctx); b=r.read(); t=b.decode("utf-8","ignore")
        m=re.search(r"<title>(.*?)</title>",t,re.S|re.I); ti=html.unescape(re.sub(r"\s+"," ",m.group(1))).strip()[:40] if m else ""
        print(f"{k:10} {r.status} {len(b):7} {ti}")
    except urllib.error.HTTPError as e:
        print(f"{k:10} {e.code} 0 HTTPError")
    except Exception as e:
        print(f"{k:10} ERR {type(e).__name__}:{str(e)[:35]}")
