#!/usr/bin/env bash # Show today's Hey tracker entries # Usage: tracker-today [--mailbox imbox] [--json] set -euo pipefail # Derive vault root from script location: Meta/scripts/ -> vault root SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" VAULT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" TRACKER="$VAULT_DIR/Meta/hey-tracker.jsonl" if [[ ! -f "$TRACKER" ]]; then echo "Tracker not found at $TRACKER" >&2 exit 1 fi TODAY=$(date -u +%Y-%m-%d) MAILBOX="" JSON=false while [[ $# -gt 0 ]]; do case "$1" in --mailbox) if [[ $# -lt 2 || "$2" == --* ]]; then echo "Usage: tracker-today [--mailbox imbox] [--json]" >&2 exit 1 fi MAILBOX="$2"; shift 2 ;; --json) JSON=true; shift ;; *) shift ;; esac done AS_JSON=$([[ "$JSON" == "true" ]] && echo "1" || echo "0") python3 - "$TRACKER" "$TODAY" "$MAILBOX" "$AS_JSON" <<'PYEOF' import json, sys tracker_path, today, mailbox_filter, as_json_flag = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] == "1" results = [] with open(tracker_path) as f: for line in f: try: e = json.loads(line) except Exception: continue if not e.get("active_at", "").startswith(today): continue if mailbox_filter and e.get("mailbox") != mailbox_filter: continue results.append(e) if as_json_flag: print(json.dumps(results, indent=2)) else: for e in results: date = e.get("active_at", "")[:16] mb = e.get("mailbox", "") sender = e.get("sender_name", "")[:30] subj = e.get("subject", "")[:60] tid = e.get("topic_id", "") print(f"{date} | {mb:8} | {sender:30} | {subj} | {tid}") PYEOF