Files
website/scripts/trains-refresh.sh

39 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Refresh of the train pokedex (/trackers/trains) on stan-ovh.
#
# ssh stan@37.187.157.191 'cd ~/dev/website-trains && git fetch -q && git checkout -q --detach origin/main \
# && bun install --frozen-lockfile >/dev/null && scripts/trains-refresh.sh'
#
# 1. bun scripts/trains-import.ts --report-new rebuilds makers, operators and types from Wikidata + English
# Wikipedia (infobox) and notes which makers/types did not exist before. Dex numbers
# are stable (types are matched by Wikidata id).
# 2. bun scripts/trains-photos.ts --missing finds Wikimedia Commons photos for types that
# have none yet (new ones included) and maker and operator logos that are missing.
# 3. bun scripts/spotters-activity.ts trains refreshes the per-country activity scores
# ("most active in NL" sort; see that script).
# 4. bun scripts/spotters-logos.ts trains --new logos for new brands / makers / operators
# (Wikidata logo or icon, then Wikipedia infobox logos)
# stdout: one JSON report {generatedAt, totals, newMakers, newTypes[] (with photo)}, plus `nl` per new
# entry and `newInNl` (new entries that are active in the Netherlands, see
# scripts/spotters-report-nl.ts). --report-new is accepted (the report is always printed).
# Progress goes to stderr. DB_URL is read from the running app container and never printed.
set -euo pipefail
cd "$(dirname "$0")/.."
if [ -z "${DB_URL:-}" ]; then
DB_URL=$(sudo docker inspect personal-website-app-1 --format '{{range .Config.Env}}{{println .}}{{end}}' |
sed -n 's/^DB_URL=//p' | sed 's/@db:5432/@127.0.0.1:5440/')
export DB_URL
fi
args=()
for a in "$@"; do [ "$a" = "--report-new" ] || args+=("$a"); done
report=$(mktemp /tmp/trains-report.XXXXXX.json)
trap 'rm -f "$report"' EXIT
bun scripts/trains-import.ts --report-new "${args[@]}" >"$report"
bun scripts/spotters-activity.ts trains >&2
bun scripts/spotters-logos.ts trains --new >&2
bun scripts/trains-photos.ts --missing --enrich "$report" --fetch | bun scripts/spotters-report-nl.ts trains