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

def strip(t):
    t = re.sub(r"<script.*?</script>", " ", t, flags=re.S|re.I)
    t = re.sub(r"<style.*?</style>", " ", t, flags=re.S|re.I)
    t = re.sub(r"<br\s*/?>", "\n", t, flags=re.I)
    t = re.sub(r"</(p|div|li|tr|h\d|td|th)>", "\n", t, flags=re.I)
    t = re.sub(r"<[^>]+>", " ", t)
    t = H.unescape(t)
    t = re.sub(r"[ \t]+", " ", t)
    t = re.sub(r"\n\s*\n+", "\n", t)
    return t.strip()

urls = {
 "gt-costs": "https://grad.gatech.edu/cost-fees",
 "gt-lang": "https://catalog.gatech.edu/admissions/grad/english-language-proficiency/",
 "gt-proc": "https://catalog.gatech.edu/admissions/grad/process-requirements/",
 "gt-adm": "https://grad.gatech.edu/admissions",
}
for k, u in urls.items():
    try:
        r = requests.get(u, headers=UA, timeout=25)
        (CACHE / (k + ".html")).write_text(r.text, encoding="utf-8", errors="ignore")
        t = strip(r.text)
        # main content
        i = max(t.find("Tuition"), t.find("Tuition"), 0)
        print("#" * 15, k, r.status_code, len(t), r.url)
        if k == "gt-costs":
            j = t.find("Tuition")
            print(t[j-300:j+2500] if j > 0 else t[:2000])
        elif k == "gt-lang":
            j = t.find("English Language Proficiency")
            print(t[j:j+2200] if j > 0 else t[:2000])
        elif k == "gt-proc":
            j = t.find("Process Requirements")
            print(t[j:j+2200] if j > 0 else t[:2000])
        else:
            print(t[:1500])
        print()
    except Exception as e:
        print(k, "ERR", str(e)[:90])
