Spaces:
Sleeping
Sleeping
File size: 5,255 Bytes
a87217c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | """
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 & 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())
|