← back to Beverlyhillsvideos

social/poster/run.sh

27 lines

#!/bin/zsh
# run.sh — 6-hourly BHV Instagram post. Alternates restaurant/store by the hour
# (slots 00/06/12/18 → restaurant, store, restaurant, store). Falls back to
# restaurant while the store library isn't deployed yet. Token + user-id come from
# the secrets master .env; LIVE posting requires BHV_IG_LIVE=1 (set by the plist).
cd "$(dirname "$0")/../.." || exit 1
HOUR=$(( 10#$(date +%H) ))
SLOT=$(( HOUR / 6 ))                 # 0..3
if (( SLOT % 2 == 1 )); then KIND=store; else KIND=restaurant; fi
# store library not deployed/public yet → fall back so a slot never posts nothing
[[ "$KIND" == "store" && ! -f data/store-films.json ]] && KIND=restaurant

LOG="social/poster/post.log"
echo "----- $(date '+%Y-%m-%d %H:%M:%S %Z') · slot=$SLOT kind=$KIND -----" >> "$LOG"
BHV_IG_KIND="$KIND" /opt/homebrew/bin/node social/poster/post-daily.mjs >> "$LOG" 2>&1
# TK-11856 rc-propagation (exit-code ONLY, no behavior change): capture the poster's rc BEFORE the
# echo and exit with it at the end (the calendar rsync below still runs, best-effort, exactly as
# before and is deliberately NOT counted). Was: always exit 0, so a failed IG post read green.
POST_RC=$?
echo "exit: $POST_RC" >> "$LOG"

# Keep calendar.agentabrams.com current: push the updated ledgers to the prod calendar
# (best-effort, non-blocking — the calendar reads these as its bundled fallback).
rsync -az social/poster/ledger.jsonl social/poster/ledger-store.jsonl \
  root@45.61.58.125:/root/public-projects/calendar-agentabrams/data/ >> "$LOG" 2>&1 || true
exit "$POST_RC"