# -*- coding: utf-8 -*-
import urllib.request, ssl, gzip, io, sys, re, os
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
hdr={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120 Safari/537.36","Accept-Language":"en-US,en;q=0.9"}
def fetch(u, t=20):
    try:
        r=urllib.request.urlopen(urllib.request.Request(u,headers=hdr),timeout=t,context=ctx)
        b=r.read()
        if r.headers.get("Content-Encoding")=="gzip": b=gzip.decompress(b)
        return r.status, len(b), b.decode("utf-8","ignore")
    except Exception as e:
        return -1, 0, str(e)

# 试更多 UT slug
candidates = [
    ("UT Mathematical Finance MMF", "https://sgs.utoronto.ca/programs/mathematical-finance/"),
    ("UT Applied Statistics MSc", "https://sgs.utoronto.ca/programs/applied-statistics/"),
    ("UT Economics MA", "https://sgs.utoronto.ca/programs/economics/"),
    ("UT Computer Science MSc", "https://sgs.utoronto.ca/programs/computer-science/"),
    ("UT Mechanical Engineering MEng", "https://sgs.utoronto.ca/programs/mechanical-engineering/"),
    ("UT Electrical & Computer Engineering MEng", "https://sgs.utoronto.ca/programs/electrical-computer-engineering/"),
    ("UT Biostatistics MSc", "https://sgs.utoronto.ca/programs/biostatistics/"),
    ("UT Epidemiology MSc", "https://sgs.utoronto.ca/programs/epidemiology/"),
]

for name, u in candidates:
    s,n,h = fetch(u)
    print(f"{s:3d} {n:7d} {name}")
