# -*- coding: utf-8 -*-
import io, sys, os, re, ssl, urllib.request, html as h
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, timeout=15):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    try:
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        b = r.read()
        return r.status, len(b), b.decode("utf-8", errors="replace")
    except Exception as e:
        return None, 0, f"ERR {type(e).__name__}"

slugs = [
    "data-science",
    "computer-science",
    "economics",
    "applied-mathematics",
    "biotechnology",
    "public-affairs",
    "biomedical-engineering",
    "mathematics",
    "statistics",
    "management",
]
for s in slugs:
    for prefix in ["academics/degree-programs","academics/graduate-programs","programs","academics"]:
        url = f"https://graduateschool.brown.edu/{prefix}/{s}/"
        st, n, body = get(url)
        if st == 200 and n > 5000:
            title = re.search(r"<title>([^<]+)</title>", body, re.I)
            print(f"OK {st} {n:>7}  {url}")
            print("   title:", h.unescape(title.group(1).strip())[:100] if title else "?")
            break
    else:
        print(f"-- {st} {n:>7}  {url}")
