Add digest command to email processor
Read-only summary of recent decisions, grouped by action with [auto]/[user] markers. Supports --recent N for multi-day lookback.
This commit is contained in:
@@ -14,7 +14,7 @@ auto decision.
|
||||
|
||||
import json
|
||||
import re
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from collections import Counter
|
||||
|
||||
@@ -200,6 +200,33 @@ def get_known_labels():
|
||||
return labels
|
||||
|
||||
|
||||
def get_recent_decisions(days=1):
|
||||
"""Return recent decisions grouped by action.
|
||||
|
||||
Args:
|
||||
days: number of days to look back (default 1 = today).
|
||||
|
||||
Returns:
|
||||
dict of action -> list of entries, e.g. {"delete": [...], "archive": [...]}.
|
||||
Returns empty dict if no decisions found in the period.
|
||||
"""
|
||||
history = _load_history()
|
||||
if not history:
|
||||
return {}
|
||||
|
||||
cutoff = datetime.now() - timedelta(days=days)
|
||||
grouped = {}
|
||||
for entry in history:
|
||||
try:
|
||||
ts = datetime.fromisoformat(entry["timestamp"])
|
||||
except (KeyError, ValueError):
|
||||
continue
|
||||
if ts >= cutoff:
|
||||
action = entry.get("action", "unknown")
|
||||
grouped.setdefault(action, []).append(entry)
|
||||
return grouped
|
||||
|
||||
|
||||
def get_all_stats():
|
||||
"""Compute aggregate statistics across the full decision history.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user