# -*- 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"
CODE = re.compile(r"\b\d{2}[\-]\d{3}\b|\b[A-Z]{2,8}[\s\-]?\d{3,4}[A-Z]?\b")
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"<[^>]+>", "\n", t)
    txt = re.sub(r"&nbsp;|&#160;", " ", txt)
    txt = re.sub(r"\n{2,}", "\n", txt)
    return txt
for name in ["r347-cmu-ini-msis", "r347-brown-cab", "r347-brown-bulletin"]:
    txt = clean(name)
    codes = sorted(set(c.strip() for c in CODE.findall(txt)))
    print("=== ", name, len(txt), "codes", len(codes), codes[:40])
    body = "\n".join([l.strip() for l in txt.split("\n") if len(l.strip()) > 25])
    for kw in ["Required Courses", "Curriculum", "Core", "credits", "tuition"]:
        i = body.find(kw)
        if i > 0:
            print(f"[{kw}]", body[i:i+420].replace("\n", " | ")[:420])
    print()
