# -*- 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()

for k in ["gt-lang", "gt-proc"]:
    t = strip((CACHE / (k + ".html")).read_text(encoding="utf-8", errors="ignore"))
    print("#" * 12, k, len(t))
    for kw in ["TOEFL", "IELTS", "Duolingo", "minimum", "Transcript", "letters of recommendation"]:
        idx = t.rfind(kw)
        if idx > 0:
            print("--", kw, "@", idx)
            print(t[max(0, idx-500):idx+900].replace("\n", " | ")[:1400])
            break
    print()

# bursar tuition
for name, u in [("bursar-home", "https://bursar.gatech.edu/"),
                ("finaid-cost", "https://finaid.gatech.edu/current-cost-overview")]:
    try:
        r = requests.get(u, headers=UA, timeout=25)
        (CACHE / (name + ".html")).write_text(r.text, encoding="utf-8", errors="ignore")
        t = strip(r.text)
        print("==", name, r.status_code, len(t), r.url)
        print(t[:900].replace("\n", " | "))
        money = re.findall(r"\$[0-9][0-9,\.]*", t)
        print("MONEY:", money[:20])
        print()
    except Exception as e:
        print(name, "ERR", str(e)[:80])
