← back to Daily Overnight Skus

run.sh

43 lines

#!/usr/bin/env bash
# Daily Overnight SKUs — runs at 6:30 AM PT Tue-Sat, emails the prior
# weeknight's after-hours orders to info@designerwallcoverings.com.
#
# Window covers 5:00 PM PT yesterday -> 6:30 AM PT today, so each run
# captures everything ordered overnight after the prior business day.
set -u
LOG=/Users/macstudio3/Projects/daily-overnight-skus/run.log
exec >>"$LOG" 2>&1
echo "=== $(date) ==="

# Load env (Shopify orders token + George creds)
set -a
. /Users/macstudio3/Projects/secrets-manager/.env 2>/dev/null
set +a
# George agent flipped to HTTPS-only (2026-06-17): http://<ip> now 400s
# ("Client sent an HTTP request to an HTTPS server") and the raw IP has no
# valid cert — use the Tailscale MagicDNS hostname (matches the george MCP).
export GMAIL_AGENT='https://kamatera.tail79cb8e.ts.net:9850'
# George basic-auth (GMAIL_BASIC_AUTH_B64) is loaded from
# secrets-manager/.env above — no longer hardcoded here. If George rotates
# the password, update secrets-manager/.env (and ~/.claude.json MCP env).
: "${GMAIL_BASIC_AUTH_B64:?GMAIL_BASIC_AUTH_B64 not set — add it to secrets-manager/.env}"

# Overnight window: yesterday 5pm PT -> today 6:30am PT.
# Job fires at 6:30 AM PT Tue-Sat, so each run captures the prior
# weeknight's after-hours orders. For Mon overnight, run fires Tue 6:30am.
TODAY_PT=$(TZ=America/Los_Angeles date +%Y-%m-%d)
YESTERDAY_PT=$(TZ=America/Los_Angeles date -v-1d +%Y-%m-%d)
START="${YESTERDAY_PT}T17:00:00-07:00"   # 5:00 PM PT prior day
END="${TODAY_PT}T06:30:00-07:00"         # 6:30 AM PT this morning

echo "[run] window: $START -> $END"

/opt/homebrew/bin/node /Users/macstudio3/.claude/skills/weekend-csv-products/generate-weekend-csv.js \
  --start "$START" \
  --end   "$END" \
  --label "Daily Overnight SKUs"

EXIT=$?
echo "[run] exit=$EXIT"
exit $EXIT