# -*- coding: utf-8 -*-
import sys, io, re, pathlib, requests, concurrent.futures as cf
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
BASE = pathlib.Path(r"D:\work buddy\2026-11-05-14-15-52")
CACHE = BASE / "cache"; CACHE.mkdir(exist_ok=True)
UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36",
      "Accept-Language": "en-US,en;q=0.9"}

urls = {
 "gatech-cs": "https://catalog.gatech.edu/programs/computer-science-ms/",
 "gatech-analytics": "https://catalog.gatech.edu/programs/analytics-ms/",
 "gatech-stat": "https://catalog.gatech.edu/programs/statistics-ms/",
 "gatech-me": "https://catalog.gatech.edu/programs/mechanical-engineering-ms/",
 "gatech-bioinfo": "https://catalog.gatech.edu/programs/bioinformatics-ms/",
 "gatech-hci": "https://catalog.gatech.edu/programs/human-computer-interaction-ms/",
 "gatech-gradcost": "https://grad.gatech.edu/costs-funding/",
 "gatech-tuition": "https://www.gatech.edu/admissions/tuition-and-fees/",
 "jhu-msf": "https://carey.jhu.edu/programs/master-science/finance",
 "cornell-acct": "https://www.johnson.cornell.edu/programs/specialized-masters/mps-in-management-accounting-specialization/",
 "nyu-msacc": "https://www.stern.nyu.edu/programs-admissions/masters-programs/ms-accounting",
 "vandy-cs": "https://computing.vanderbilt.edu/mscs/",
 "dartmouth-cs": "https://graduate.dartmouth.edu/programs/computer-science-ms",
}

def fetch(k, u):
    try:
        r = requests.get(u, headers=UA, timeout=20, allow_redirects=True)
        txt = r.text
        head = txt[:200].replace("\n", " ")
        cf = "cloudflare" in r.headers.get("Server", "").lower() or "Just a moment" in head or "cf-mitigated" in {kk.lower() for kk in r.headers}
        (CACHE / (k + ".html")).write_text(txt, encoding="utf-8", errors="ignore")
        return k, r.status_code, len(txt), r.url, cf, ("<!DOCTYPE" in txt[:400] or "<html" in txt[:400].lower())
    except Exception as e:
        return k, "ERR", str(e)[:90], "", "", ""

with cf.ThreadPoolExecutor(10) as ex:
    for res in ex.map(lambda kv: fetch(*kv), urls.items()):
        print(res)
