# -*- coding: utf-8 -*-
import urllib.request, ssl, re, io, sys, os, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")

SCTX = ssl.create_default_context()
SCTX.check_hostname = False
SCTX.verify_mode = ssl.CERT_NONE

def probe(url, timeout=15):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    try:
        r = urllib.request.urlopen(req, timeout=timeout, context=SCTX)
        return r.status, len(r.read())
    except Exception as e:
        return -1, str(e)[:80]

cands = [
    ("nyu-math", "https://bulletins.nyu.edu/graduate/arts-science/programs/mathematics-ms/"),
    ("nyu-phys", "https://bulletins.nyu.edu/graduate/arts-science/programs/physics-ms/"),
    ("ut-susm", "https://www.sgs.utoronto.ca/programs/sustainability-management/"),
    ("ut-foracct", "https://www.sgs.utoronto.ca/programs/forensic-accounting/"),
    ("ut-mpacc", "https://www.sgs.utoronto.ca/programs/management-and-professional-accounting/"),
    ("ut-hr", "https://www.sgs.utoronto.ca/programs/industrial-relations-human-resources/"),
    ("nyu-skel", "https://bulletins.nyu.edu/graduate/arts-science/programs/human-skeletal-biology-ms/"),
]

idx = open("index_main.html", encoding="utf-8").read()
prog_seg = idx[idx.find("const PROGRAMS="):idx.find("const CATD=")]

for tag, url in cands:
    st, sz = probe(url)
    # 去重：Grep PROGRAMS 里是否有相关英文名
    en_key = url.rstrip("/").split("/")[-1].replace("-", " ")
    dup = "DUP" if en_key in prog_seg.lower() else "NEW"
    print(f"{tag:12s} {st} {sz:>8} {dup}  {url}")
