# -*- coding: utf-8 -*-
import re, io, sys, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
slugs=["aerospace-engineering-ms","materials-science-engineering-ms","physics-ms","public-policy-ms","human-computer-interaction-ms"]
for s in slugs:
    txt=open(f"_49_{s}.html",encoding="utf-8").read()
    body=re.sub(r"<script[\s\S]*?</script>","",txt)
    body=re.sub(r"<style[\s\S]*?</style>","",body)
    # find credit totals / options / track
    print("===",s)
    # total credit hours
    for m in re.finditer(r"([0-9]+)\s*(?:Credit Hours|Credit Hours Required|Hours|Total Credits)",body):
        ctx=re.sub(r"<[^>]+>"," ",body[max(0,m.start()-120):m.end()+30])
        print("  CR:",re.sub(r"\s+"," ",ctx).strip()[:160])
    # thesis/non-thesis option
    for m in re.finditer(r"(Thesis|Non-?[Tt]hesis|Course[- ]Only|Option|Track|Concentration)",body):
        ctx=re.sub(r"<[^>]+>"," ",body[max(0,m.start()-60):m.end()+120])
        c=re.sub(r"\s+"," ",ctx).strip()
        if len(c)>30: print("  OPT:",c[:160])
    # online / distance / part-time
    for kw in ["distance learning","online","part-time","working professionals"]:
        if kw.lower() in body.lower():
            idx=body.lower().find(kw.lower())
            ctx=re.sub(r"<[^>]+>"," ",body[max(0,idx-80):idx+150])
            print("  FLAG:",re.sub(r"\s+"," ",ctx).strip()[:180])
