# -*- coding: utf-8 -*-
import io, sys, os, re, ssl, urllib.request
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
UA = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36"}

def get(url, timeout=20):
    try:
        req = urllib.request.Request(url, headers=UA)
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        return r.status, r.read().decode("utf-8", errors="ignore")
    except Exception as e:
        return -1, str(e)

# GaTech catalog 项目索引页
url = "https://catalog.gatech.edu/programs/"
st, body = get(url)
slugs = re.findall(r'href="(/programs/([^/"]+)/?)"', body)
slugs = sorted(set([s[1] for s in slugs if not s[1].startswith("#")]))

# 已录的 gatech details
existing = set()
for f in os.listdir("details"):
    if f.startswith("gatech-") and f.endswith(".html"):
        existing.add(f.replace(".html", "").replace("gatech-", ""))

# 筛选硕士 slug（排除 BS / PhD / certificate / 双学位）
ms_slugs = [s for s in slugs if s.endswith(("-ms", "-mcm", "-mpa", "-mem", "-msp", "-ms-", "-ms_")) or "-ms-" in s or s.endswith("-mps") or s.endswith("-pmase") or s.endswith("-march") or s.endswith("-mid") or s.endswith("-mred") or s.endswith("-msud") or s.endswith("-msab") or s.endswith("-msce") or s.endswith("-msne") or s.endswith("-msm") or s.endswith("-msch") or s.endswith("-msstat") or s.endswith("-msbio") or s.endswith("-msche") or s.endswith("-mscee") or s.endswith("-mse") or s.endswith("-msae") or s.endswith("-msppe") or s.endswith("-mshts") or s.endswith("-msint") or s.endswith("-msmgt") or s.endswith("-msw") or s.endswith("-ma") or s.endswith("-msa") or s.endswith("-mfa") or s.endswith("-mus") or s.endswith("-mm") or s.endswith("-mps")]
# 排除 BS / PhD / certificate
ms_slugs = [s for s in ms_slugs if "-bs" not in s and "-phd" not in s and "certificate" not in s and "-dual" not in s]

# 未录的
new_ms = [s for s in ms_slugs if s not in existing]
print("new master slugs:", len(new_ms))
for s in new_ms[:50]:
    print(" -", s)
