# -*- 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 = {
 "gt-progindex": "https://catalog.gatech.edu/programs/",
 "gt-robotics": "https://catalog.gatech.edu/programs/robotics-ms/",
 "gt-bme": "https://catalog.gatech.edu/programs/biomedical-engineering-ms/",
 "gt-bioe": "https://catalog.gatech.edu/programs/bioengineering-ms/",
 "gt-biology": "https://catalog.gatech.edu/programs/biology-ms/",
 "gt-medphys": "https://catalog.gatech.edu/programs/medical-physics-ms/",
 "gt-mgmt": "https://catalog.gatech.edu/programs/management-ms/",
 "gt-bcfm": "https://catalog.gatech.edu/programs/building-construction-and-facility-management-ms/",
 "gt-econ": "https://catalog.gatech.edu/programs/economics-ms/",
 "gt-math": "https://catalog.gatech.edu/programs/mathematics-ms/",
 "gt-urbanan": "https://catalog.gatech.edu/programs/urban-analytics-ms/",
 "bursar-fall26": "https://www.bursar.gatech.edu/Fall_2026",
}

def fetch(k, u):
    try:
        r = requests.get(u, headers=UA, timeout=25, allow_redirects=True)
        txt = r.text
        cf = "Just a moment" in txt[:400] or "cloudflare" in r.headers.get("Server", "").lower()
        (CACHE / (k + ".html")).write_text(txt, encoding="utf-8", errors="ignore")
        return k, r.status_code, len(txt), r.url[:110], cf
    except Exception as e:
        return k, "ERR", str(e)[:80], "", ""

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