Spaces:
Sleeping

File size: 1,788 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
"""
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())