#!/usr/bin/env bash # Run the daily-file scrape and then serve the dashboard. # # Usage: # ./start.sh # scrape today, then serve on :8000 # ./start.sh --force # force re-fetch even if cached # DATE=2026-09-01 ./start.sh # scrape a specific date # # Environment overrides: # DATE - YYYY-MM-DD to scrape (default: today) # PORT - dashboard port (default: 8000) # HOST - dashboard bind address (default: 127.0.0.1) # FORCE - set to 1 to pass --force to ingest # SKIP_SCRAPE - set to 1 to skip the scrape step entirely set -uo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT="${SCRIPT_DIR}" cd "${ROOT}" || { echo "[start] cannot cd to ${ROOT}" >&2; exit 2; } PY="${PYTHON:-python3}" DATE="${DATE:-$(date +%F)}" PORT="${PORT:-8000}" HOST="${HOST:-127.0.0.1}" FORCE_FLAG="" if [ "${FORCE:-0}" = "1" ]; then FORCE_FLAG="--force" fi # ── Step 1: scrape ────────────────────────────────────────────────────── if [ "${SKIP_SCRAPE:-0}" != "1" ]; then echo "===================================================================" echo "[start] scrape date=${DATE} root=${ROOT}" echo "===================================================================" "${PY}" -u -m scraper ingest --date "${DATE}" ${FORCE_FLAG} INGEST_EXIT=$? case "${INGEST_EXIT}" in 0) echo "[start] scrape OK (ok / cached / no publication)" ;; 1) echo "[start] scrape FAILED (see cache/request_log.jsonl)" >&2 ;; *) echo "[start] scrape ERROR (exit ${INGEST_EXIT})" >&2 ;; esac # Also fetch the chamber events calendar (non-fatal if it fails). if [ "${SKIP_EVENTS:-0}" != "1" ]; then "${PY}" -u -m scraper ingest --date "${DATE}" ${FORCE_FLAG} \ --store-events --db db/daily_file.sqlite 2>&1 | head -5 fi # Don't abort on scrape failure — the dashboard can still serve cached data. if [ "${INGEST_EXIT}" -ne 0 ]; then echo "[start] continuing to dashboard despite scrape exit ${INGEST_EXIT}" >&2 fi else echo "[start] scrape skipped (SKIP_SCRAPE=1)" fi # ── Step 2: serve ─────────────────────────────────────────────────────── echo "" echo "===================================================================" echo "[start] dashboard http://${HOST}:${PORT}/" echo "===================================================================" exec "${PY}" -u -m scraper dashboard --host "${HOST}" --port "${PORT}" --log