# -*- coding: utf-8 -*-
import io, sys, ssl, urllib.request, re, html as _html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
ctx = ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
slugs = [
    "nutrition",
    "microbiology-immunology",
    "genetics",
    "neuroscience",
    "health-policy-management",
    "epidemiology",
    "accounting",
    "business-administration",
    "management-society",
    "environment-ecology",
    "geography",
    "sociology",
]
for s in slugs:
    url = f"https://catalog.unc.edu/graduate/schools-departments/{s}/"
    try:
        req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
        r = urllib.request.urlopen(req, timeout=15, context=ctx)
        b = r.read()
        h = b.decode("utf-8", errors="ignore")
        text = re.sub(r"<script[\s\S]*?</script>"," ",h,flags=re.I)
        text = re.sub(r"<style[\s\S]*?</style>"," ",text,flags=re.I)
        text = re.sub(r"<[^>]+>"," ",text)
        text = _html.unescape(text); text = re.sub(r"\s+"," ",text)
        i = text.lower().find("master")
        seg = text[max(0,i-80):i+700] if i>=0 else "(no master keyword)"
        excl = "terminal" in text.lower() or "does not offer" in text.lower()
        print(f"=== {s} | {len(b)}B | excl={excl}")
        print(seg[:800])
        print()
    except Exception as e:
        print(f"=== {s} | ERR {e}")
