← back to Trending Dw
scripts/refresh.sh
53 lines
#!/bin/bash
# trending-dw refresh. Two paths, clearly separated so spend is never accidental:
#
# LIVE (data actually moves):
# 1. GATED, metered — run the design-trend-scout agent (Exa) to research current bestsellers.
# It is the ONLY step that costs money; it is NOT run here. Have it write its per-item
# research to a feed JSON (shape: {scannedAt, items:[{title,company,marketplace,style,
# color,priceBand,signal,signalRank,url}]}) — e.g. data/scout-feed.json.
# 2. $0, offline — map that feed into the board + re-attach our-own images + reload:
# bash scripts/refresh.sh --scout data/scout-feed.json
#
# SEED (static/dev only — re-bakes the committed 2026-07-02 research; data does NOT move):
# bash scripts/refresh.sh --seed
#
# Running with NO args prints this guidance and does nothing (so a stray cron/hand-run can't
# silently re-bake stale data and pretend it refreshed).
set -e
cd "$(dirname "$0")/.."
reload(){ if command -v pm2 >/dev/null 2>&1 && pm2 id trending-dw >/dev/null 2>&1; then pm2 restart trending-dw; fi; }
case "${1:-}" in
--scout)
FEED="${2:?usage: refresh.sh --scout <scout-feed.json>}"
node scripts/scout-to-bestsellers.js "$FEED" # $0 deterministic mapper → data/bestsellers.json (today's date)
node scripts/attach-images.js # re-attach our-own images (mapper rewrites the file) + GAP flags
node scripts/localize-images.js # download any remote card images → self-host from /assets/wpb/
reload
echo "LIVE refresh done from $FEED — $(date)"
;;
--seed)
node scripts/seed.js # re-bake committed static research (spottedAt hardcoded)
node scripts/attach-images.js
reload
echo "SEED re-bake done (STATIC data — does not move the vintage) — $(date)"
;;
*)
cat <<'USAGE'
trending-dw refresh — pick a path:
LIVE (data moves): bash scripts/refresh.sh --scout <scout-feed.json>
where <scout-feed.json> was produced by a GATED, metered design-trend-scout run.
This script does NOT run the metered Exa pull — that stays a separate approved step.
SEED (static/dev): bash scripts/refresh.sh --seed
re-bakes the committed 2026-07-02 research; the freshness badge will NOT clear.
No path given → nothing done (refusing to silently re-bake stale data).
USAGE
exit 0
;;
esac