# -*- coding: utf-8 -*-
import sys, io, re, pathlib, 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")

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

def show(k, kws, span=1200):
    t = txt((CACHE / (k + ".html")).read_text(encoding="utf-8", errors="ignore"))
    print("#" * 18, k, len(t))
    for kw in kws:
        i = t.find(kw)
        if i >= 0:
            print("--", kw)
            print(t[max(0, i-200):i+span])
    print()

show("cu-career", ["Career outcomes", "Median", "salary", "Employment"], 1400)
show("nyu-tuition", ["Tuition", "Cost of Attendance", "Total"], 1400)
show("nyu-academics", ["Curriculum", "courses", "30 credits"], 1600)
show("nyu-career", ["Employment", "employers", "rate"], 1200)
