#!/usr/bin/env bash # Voice notes -> Notion Meeting Recordings sync. # Pulls new Voicenotes recordings since the watermark, prints JSON for the worker. # Exit 0 with [] when nothing new or auth fails (worker stays silent on auth failure). set -u STATE_DIR="${HOME}/hooks/state/voicenotes-notion-sync" mkdir -p "$STATE_DIR" MARK="$STATE_DIR/watermark" SINCE="1970-01-01T00:00:00Z" [ -f "$MARK" ] && SINCE="$(cat "$MARK")" OUT="$(mktemp)" if ! ~/workspace/skills/voicenotes/bin/vn-recordings --since "$SINCE" > "$OUT" 2>/dev/null; then echo "AUTH_FAILED" rm -f "$OUT" exit 0 fi python3 - "$OUT" "$MARK" <<'PYEOF' import json, sys out_path, mark_path = sys.argv[1], sys.argv[2] try: recs = json.load(open(out_path)) except Exception: print("[]") sys.exit(0) if not isinstance(recs, list): recs = [] # newest watermark latest = None for r in recs: ts = r.get("recorded_at") or r.get("created_at") if ts and (latest is None or ts > latest): latest = ts print(json.dumps([{ "id": r.get("id"), "title": r.get("title"), "recorded_at": r.get("recorded_at"), "duration_ms": r.get("duration"), "tags": r.get("tags", []), "transcript": (r.get("transcript") or "")[:12000], } for r in recs])) if latest: open(mark_path, "w").write(latest) PYEOF rm -f "$OUT"