# -*- coding: utf-8 -*-
import sys, io, re, pathlib
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
BASE = pathlib.Path(r"D:\work buddy\2026-11-05-14-15-52")
CACHE = BASE / "cache"

def text(p):
    t = p.read_text(encoding="utf-8", errors="ignore")
    t = re.sub(r"<script.*?</script>", " ", t, flags=re.S)
    t = re.sub(r"<style.*?</style>", " ", t, flags=re.S)
    t = re.sub(r"<[^>]+>", "\n", t)
    t = re.sub(r"&nbsp;", " ", t).replace("&amp;", "&")
    lines = [x.strip() for x in t.split("\n")]
    return [x for x in lines if x]

# 1) BCFM slug in index
idx = text(CACHE / "gt-progindex.html")
hits = [x for x in idx if re.search(r"Facility|Construction|Building", x, re.I)]
print("== BCFM candidates ==")
for h in hits[:12]: print(h)
print()
html = (CACHE / "gt-progindex.html").read_text(encoding="utf-8", errors="ignore")
for m in re.finditer(r'href="(/programs/[^"]+)"[^>]*>([^<]*)<', html):
    if re.search(r"Facilit|Construct|Building", m.group(2), re.I):
        print("LINK:", m.group(1), "|", m.group(2).strip())
