Spaces:
Sleeping

curium-intel / scripts /send_adhoc_digest.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
1.79 kB
"""
Send the full aggregate digest to any ad-hoc email address.
Builds the same cross-team digest that Adela receives (all colleagues'
leads, combined view) and sends it to the specified address.
Usage:
python scripts/send_adhoc_digest.py jodie@example.com "Jodie"
python scripts/send_adhoc_digest.py jodie@example.com # name defaults to address
This is intentionally a thin wrapper β€” the digest content comes from
build_aggregate_digest() so it stays in sync with whatever the weekly
digest looks like on any given run.
"""
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
def main() -> int:
if len(sys.argv) < 2:
print("Usage: send_adhoc_digest.py <email> [name]")
return 1
to_email = sys.argv[1].strip()
recipient_name = sys.argv[2].strip() if len(sys.argv) > 2 else to_email
print(f"β†’ Building aggregate digest for {recipient_name}…")
bundle = weekly_digest.build_aggregate_digest(recipient_name=recipient_name)
print(f" Subject : {bundle['subject']}")
print(f" Leads : {bundle.get('n_leads', '?')}")
print(f"β†’ Sending to {to_email}…")
result = mailer.send(
to_email=to_email,
subject=bundle["subject"],
html=bundle["html"],
text_fallback=bundle.get("text_fallback", ""),
)
if result.get("success"):
print("βœ“ Sent")
return 0
else:
print(f"βœ— Failed: {result.get('message')}")
return 1
if __name__ == "__main__":
raise SystemExit(main())