blob: 2d5b3291a971d18610f086494c1f1d3a2b0f63bc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
|