"""Verify what is stored NOW, reading filenames from PocketBase rather than hardcoding them. Confirms the signature images survived the upload. """ import io import json import urllib.parse import urllib.request from pathlib import Path from pypdf import PdfReader JEI = Path(r"C:\Users\SJ\.minimax-agent\projects\JEI") env = {} for line in (JEI / ".env.local").read_text(encoding="utf-8").splitlines(): line = line.strip() if line and not line.startswith("#") and "=" in line: k, v = line.split("=", 1) env[k.strip()] = v.strip().strip('"').strip("'") PB = env.get("NEXT_PUBLIC_PB_URL") or env["PB_URL"] TOK = env["PB_TOKEN"] SLOTS = [ ("resolution.signed_letter", "pbc_266170881", "e0dbxprazb70rqx", "signed_letter"), ("resignation.letter", "ysterbaard_director_resignations", "8cfie18uhgy0n0o", "letter"), ("resignation.signature", "ysterbaard_director_resignations", "8cfie18uhgy0n0o", "signature"), ] def api(path): req = urllib.request.Request(f"{PB}{path}", headers={"Authorization": TOK}) with urllib.request.urlopen(req, timeout=120) as r: return json.loads(r.read().decode()) def images(reader): n = 0 for p in reader.pages: try: n += len(p.images) except Exception: pass return n for label, col, rid, field in SLOTS: rec = api(f"/api/collections/{col}/records/{rid}") fname = rec.get(field) if not fname: print(f"{label}: EMPTY") continue url = f"{PB}/api/files/{col}/{rid}/{urllib.parse.quote(fname)}" req = urllib.request.Request(url, headers={"Authorization": TOK}) with urllib.request.urlopen(req, timeout=120) as r: b = r.read() rd = PdfReader(io.BytesIO(b)) txt = " ".join((p.extract_text() or "") for p in rd.pages).lower() has_underscores = "_____" in " ".join((p.extract_text() or "") for p in rd.pages) print(f"{label}") print(f" file : {fname}") print(f" size : {len(b)} B pages={len(rd.pages)}") print(f" IMAGES : {images(rd)} <-- signature scans") print(f" has blank signature rules: {has_underscores}") print()