Spaces:
Sleeping

curium-intel / scripts /send_lgr_report.py
mipwr-admin's picture
Sync from GitHub main β€” ERP priority, WMCA/Shropshire watchlist, network preserve-owners fix (a7395ea)
a87217c verified
Raw History Blame Contribute Delete
5.26 kB
"""
Email the latest LGR landscape report (Word doc attached) to named
recipients with a short covering note. Internal only.
Usage:
python scripts/send_lgr_report.py "Jordan:jordanhart@curiumsolutions.com" "Stu:stuartbailey@curiumsolutions.com"
python scripts/send_lgr_report.py --dry-run "Jordan:..." "Stu:..."
Each recipient arg is "Name:email". Attaches the most recent
intel_assets/lgr_landscape_*.docx.
"""
from __future__ import annotations
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT))
try:
from dotenv import load_dotenv
load_dotenv(REPO_ROOT / ".env", override=False)
except ImportError:
pass
import mailer
import weekly_digest
INTEL_DIR = REPO_ROOT / "intel_assets"
DRY_RUN = "--dry-run" in sys.argv
def _latest_docx() -> Path | None:
docs = sorted(INTEL_DIR.glob("lgr_landscape_*.docx"))
# Skip Word lock files
docs = [d for d in docs if not d.name.startswith("~$")]
return docs[-1] if docs else None
def _covering_html(name: str, report_date: str) -> str:
try:
fb = weekly_digest._feedback_prompt_html(recipient_name=name)
except Exception:
fb = ""
return f"""
<div style="font-family:Calibri,Arial,sans-serif;max-width:640px;margin:0 auto;">
<h2 style="color:#1a237e;border-bottom:2px solid #1a237e;padding-bottom:6px;">
πŸ›οΈ UK LGR Landscape β€” corrected & re-verified report</h2>
<p>Hi {name},</p>
<p><strong>Apologies first.</strong> The LGR report I sent earlier today
contained factual errors β€” most importantly it claimed Oxfordshire and
several other counties had ministerial decisions in March 2026. They had
not. That was a fabrication by the report generator, and I should have
caught it before sending. Please bin the earlier version.</p>
<p><strong>What went wrong, and what's fixed:</strong> the tool was
letting the AI assert confident specifics that weren't backed by a source.
I've rebuilt the generator so <strong>every factual claim must now trace
to a cited source</strong>, decision status can't be overstated, and
anything not found in sources is left as "unknown" rather than invented.
This attached version was produced under those rules and I've
independently verified the key facts against gov.uk before sending.</p>
<p><strong>The corrected position on decisions:</strong></p>
<ul style="font-size:0.92em;color:#333;">
<li><strong>Decisions MADE on 25 March 2026</strong> (verified, gov.uk
decision letters): Surrey (2 unitaries, vesting Apr 2027), Essex (5,
Apr 2028), Hampshire &amp; IoW area (5), Norfolk (3), Suffolk (3).</li>
<li><strong>Decisions still PENDING β€” expected ~mid-July 2026:</strong>
Hertfordshire, Kent, Oxfordshire, Warwickshire, Worcestershire,
Nottinghamshire, Leicestershire, Lincolnshire and others. No decision
has been made on these yet.</li>
<li>Warm routes (from our own contacts, not web): Hertfordshire via
Sandy Walkington (Chair, Piers's 1st-degree) + Angie Ridgwell (CEO);
Essex via Peter Shakespear (ex-Essex, our Staffs exec sponsor).</li>
</ul>
<p style="font-size:0.92em;color:#333;">Every claim in the attached report
carries an inline [n] citation to the References section. The report opens
with a caveat line reminding you to verify dates, names and notice numbers
against the cited source before acting β€” please do, especially on anything
you'd put in front of a client.</p>
<p>Thanks for the catch, and sorry again for the earlier version.</p>
<p>Best,<br>Curium Lead Intelligence</p>
{fb}
</div>"""
def main() -> int:
# Parse "Name:email" recipient args (skip flags)
recipients = []
for arg in sys.argv[1:]:
if arg.startswith("--"):
continue
if ":" in arg:
name, email = arg.split(":", 1)
recipients.append((name.strip(), email.strip()))
if not recipients:
print("No recipients. Pass 'Name:email' args.")
return 1
docx = _latest_docx()
if not docx:
print("No lgr_landscape_*.docx found in intel_assets/.")
return 1
import re
m = re.search(r"(\d{4}-\d{2}-\d{2})", docx.name)
report_date = m.group(1) if m else "latest"
subject = f"UK LGR Landscape report β€” {report_date} (deep sweep)"
print(f"β†’ Report: {docx.name} ({docx.stat().st_size//1024} KB)")
sent = []
for name, email in recipients:
html = _covering_html(name, report_date)
if DRY_RUN:
print(f" [dry-run] would send to {name} <{email}> with {docx.name} attached")
sent.append(name)
continue
result = mailer.send(to_email=email, subject=subject, html=html,
attachments=[str(docx)])
if result.get("success"):
print(f" βœ“ {name} β†’ {email}")
sent.append(name)
else:
print(f" βœ— {name} β†’ {result.get('message')}")
print(f"\nSent to: {sent}")
return 0
if __name__ == "__main__":
raise SystemExit(main())