diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/build-oracle.sh | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/build-oracle.sh b/scripts/build-oracle.sh new file mode 100755 index 0000000..2d5b329 --- /dev/null +++ b/scripts/build-oracle.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# build-oracle.sh — generate the regression oracle snapshot for the calendar +# engine by fetching the authoritative General Roman Calendar from calapi +# (calendarium-romanum) month by month, 2020-2040. +# +# NOT run by `go test`. Requires network + curl + jq. Run from the repo root: +# scripts/build-oracle.sh +# Writes internal/calendar/testdata/oracle-2020-2040.json as +# { "YYYY-MM-DD": {"season": "...", "rank_num": N.N}, ... } +# where season/rank_num are the top celebration's (celebrations[0]). +set -euo pipefail + +base="http://calapi.inadiutorium.cz/api/v0/en/calendars/general-en" +out="internal/calendar/testdata/oracle-2020-2040.json" +mkdir -p "$(dirname "$out")" +tmp="$(mktemp)" + +echo "{" > "$tmp" +first=1 +for y in $(seq 2020 2040); do + for m in $(seq 1 12); do + month_json="$(curl -sf "$base/$y/$m")" + # emit "date": {"season":..., "rank_num":...} for each day, comma-separated + rows="$(printf '%s' "$month_json" | jq -r '.[] | "\(.date)\t\(.season)\t\(.celebrations[0].rank_num)"')" + while IFS=$'\t' read -r date season rank; do + [ -n "$date" ] || continue + if [ "$first" -eq 1 ]; then first=0; else printf ",\n" >> "$tmp"; fi + printf ' "%s": {"season": "%s", "rank_num": %s}' "$date" "$season" "$rank" >> "$tmp" + done <<< "$rows" + done + echo " ...$y done" >&2 +done +printf "\n}\n" >> "$tmp" +mv "$tmp" "$out" +echo "wrote $out" >&2 |
