← back to Astek Landing

scripts/monthly-refresh.sh

42 lines

#!/bin/bash
# Astek monthly full refresh: re-scrape astek.com -> astek_catalog -> rebuild
# snapshot -> deploy the fresh data to the live (gated, internal) microsite.
#
# The existing com.steve.astek-data-refresh only REBUILDS the local snapshot
# from the DB every 15 min; it never re-scrapes the vendor and never deploys.
# This monthly job closes both gaps. Scrape+rebuild are $0 local; the deploy
# targets an internal basic-auth microsite (no Shopify, no prices) so an
# unattended monthly push is low-risk.
set -uo pipefail

# launchd hands us a minimal PATH — restore node + ssh/rsync (deploy.sh needs them).
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

PROJ="/Users/macstudio3/Projects/astek-landing"
LOG="/tmp/astek-monthly-refresh.log"
cd "$PROJ" || { echo "$(date '+%F %T') FATAL cd $PROJ failed" >>"$LOG"; exit 1; }

echo "===== $(date '+%F %T') astek monthly refresh START =====" >>"$LOG"

echo "[1/3] scrape astek.com -> astek_catalog" >>"$LOG"
if ! node scripts/scrape-astek.js >>"$LOG" 2>&1; then
  echo "$(date '+%F %T') SCRAPE FAILED — aborting (snapshot + live left untouched)" >>"$LOG"; exit 1
fi

echo "[2/3] rebuild data/products.json" >>"$LOG"
if ! node scripts/build-products-json.js >>"$LOG" 2>&1; then
  echo "$(date '+%F %T') REBUILD FAILED — aborting before deploy" >>"$LOG"; exit 1
fi

# Commit the refreshed data so the deploy ships a tracked snapshot.
git add data/products.json data/astek-raw.json 2>/dev/null
git -c user.email="steve@designerwallcoverings.com" \
    commit -q -m "data: astek monthly refresh $(date '+%F')" 2>/dev/null || true

echo "[3/3] deploy fresh snapshot to Kamatera" >>"$LOG"
if ! bash /Users/macstudio3/Projects/_shared/scripts/deploy.sh >>"$LOG" 2>&1; then
  echo "$(date '+%F %T') DEPLOY FAILED — local snapshot is fresh, live is stale" >>"$LOG"; exit 1
fi

echo "===== $(date '+%F %T') astek monthly refresh DONE =====" >>"$LOG"