vault-sync: 2026-09-16 00:00 (jimmy)
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
# Filter Hey tracker by mailbox
|
||||
# Usage: tracker-mailbox <imbox|feedbox|trailbox> [days] [--json]
|
||||
set -euo pipefail
|
||||
|
||||
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
|
||||
|
||||
MAILBOX=""
|
||||
DAYS=7
|
||||
JSON=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--json) JSON=true; shift ;;
|
||||
[0-9]*)
|
||||
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
|
||||
echo "Error: days must be a positive integer" >&2
|
||||
exit 1
|
||||
fi
|
||||
DAYS="$1"; shift ;;
|
||||
*)
|
||||
if [[ -z "$MAILBOX" ]]; then
|
||||
MAILBOX="$1"
|
||||
fi
|
||||
shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$MAILBOX" ]]; then
|
||||
echo "Usage: tracker-mailbox <imbox|feedbox|trailbox> [days] [--json]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
AS_JSON=$([[ "$JSON" == "true" ]] && echo "1" || echo "0")
|
||||
|
||||
python3 - "$TRACKER" "$MAILBOX" "$DAYS" "$AS_JSON" <<'PYEOF'
|
||||
import json, sys
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
tracker_path, mailbox, days, as_json_flag = sys.argv[1], sys.argv[2], int(sys.argv[3]), sys.argv[4] == "1"
|
||||
cutoff = (datetime.now(timezone.utc) - timedelta(days=days)).strftime("%Y-%m-%d")
|
||||
results = []
|
||||
with open(tracker_path) as f:
|
||||
for line in f:
|
||||
try:
|
||||
e = json.loads(line)
|
||||
except Exception:
|
||||
continue
|
||||
if e.get("mailbox") != mailbox:
|
||||
continue
|
||||
if e.get("active_at", "")[:10] < cutoff:
|
||||
continue
|
||||
results.append(e)
|
||||
|
||||
if as_json_flag:
|
||||
print(json.dumps(results, indent=2))
|
||||
else:
|
||||
for e in results:
|
||||
date = e.get("active_at", "")[:10]
|
||||
sender = e.get("sender_name", "")[:30]
|
||||
subj = e.get("subject", "")[:60]
|
||||
tid = e.get("topic_id", "")
|
||||
print(f"{date} | {sender:30} | {subj} | {tid}")
|
||||
PYEOF
|
||||
Reference in New Issue
Block a user