# -*- coding: utf-8 -*-
import io, sys, re, ssl, urllib.request
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

cands = [
    "https://ame.nd.edu/graduate/msme/",
    "https://ame.nd.edu/graduate/m-s-in-mechanical-engineering-msme/",
    "https://ame.nd.edu/graduate/mechanical-engineering-msme/",
    "https://ame.nd.edu/graduate/master-of-science-in-mechanical-engineering/",
]
for u in cands:
    req = urllib.request.Request(u, headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"})
    try:
        r = urllib.request.urlopen(req, timeout=15, context=ctx)
        raw = r.read().decode("utf-8","ignore")
        print("OK", r.status, len(raw), u)
    except Exception as e:
        print("ERR", type(e).__name__, str(e)[:80], u)

# handbook PDF
pdf = "https://ame.nd.edu/wp-content/uploads/sites/4/2025/11/Handbook_2025_2026.docx.pdf"
req = urllib.request.Request(pdf, headers={"User-Agent":"Mozilla/5.0"})
try:
    r = urllib.request.urlopen(req, timeout=20, context=ctx)
    data = r.read()
    open("_ame_handbook.pdf","wb").write(data)
    print("PDF bytes", len(data))
except Exception as e:
    print("PDF ERR", type(e).__name__, str(e)[:120])
