# -*- coding: utf-8 -*-
import re, sys, io, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
slugs = [
 "applied-positive-psychology-mapp",
 "government-administration-mpa",
 "international-mpa",
 "health-care-innovation-mhci",
 "public-health-mph",
]
out = []
for s in slugs:
    body = open(f"_raw_{s}.html", encoding="utf-8").read()
    text = re.sub(r"<script[\s\S]*?</script>", " ", body)
    text = re.sub(r"<style[\s\S]*?</style>", " ", text)
    text = re.sub(r"<[^>]+>", " ", text)
    text = re.sub(r"\s+", " ", text).strip()
    out.append(f"\n========== {s} (textlen={len(text)}) ==========")
    # find main content area
    for kw in ["Program of Study","Overview","Degree Requirements","Curriculum","About the Program","The program","This program"]:
        i = text.lower().find(kw.lower())
        if i >= 0:
            out.append(f"--- {kw} ---")
            out.append(text[i:i+2500])
            break
    else:
        out.append(text[:2500])
    # keywords
    for kw in ["online","executive","part-time","working professional","evening","distance","postdoctoral","MBA","Wharton","full-time","on-campus","hybrid","format","duration","units","course units","CU"]:
        for m in re.finditer(kw, text, re.IGNORECASE):
            i = m.start()
            out.append(f"[KW {kw}] ...{text[max(0,i-100):i+220]}...")
            break
open("_extract89_out.txt","w",encoding="utf-8").write("\n".join(out))
print("written", len("\n".join(out)))
