# -*- coding: utf-8 -*-
import sys, io, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
BASE = r"D:\work buddy\2026-11-05-14-15-52\cache"
MONEY = re.compile(r"\$\s?\d[\d,\.]*")
DATE = re.compile(r"(20\d{2}-\d{2}-\d{2}|January\s+\d{1,2}|February\s+\d{1,2}|March\s+\d{1,2}|April\s+\d{1,2}|October\s+\d{1,2}|November\s+\d{1,2}|December\s+\d{1,2})")
def clean(name):
    t = open(BASE + "\\" + name + ".html", encoding="utf-8", errors="replace").read()
    t = re.sub(r"<script.*?</script>|<style.*?</style>", " ", t, flags=re.S)
    txt = re.sub(r"<[^>]+>", " ", t)
    txt = re.sub(r"&nbsp;|&#160;|&amp;", " ", txt)
    txt = re.sub(r"\s{2,}", " ", txt)
    return txt
for name in ["r347-emory-ms-req", "r347-rice-mcs", "r347-rice-mds", "r347-emory-grad-ms"]:
    txt = clean(name)
    mo = sorted(set(MONEY.findall(txt)))[:12]
    dt = sorted(set(DATE.findall(txt)))[:12]
    print("===", name, "chars", len(txt), "money", mo, "dates", dt)
    for kw in ["deadline", "Deadline", "tuition", "Tuition", "application fee"]:
        i = txt.find(kw)
        if i > 0:
            print(f"  [{kw}]", txt[max(0,i-120):i+260])
print("=== uchi-registrar-cat links")
t = open(BASE + r"\r347-uchi-registrar-cat.html", encoding="utf-8", errors="replace").read()
for h in re.findall(r'href="([^"]+)"', t):
    if re.search(r"(catalog|acalog|course)", h, re.I):
        print("  ", h[:120])
