Add reverse date order to fetch-year script
build / build (push) Successful in 3m50s

This commit is contained in:
2026-09-30 16:31:27 +02:00
parent 8653076c97
commit 29e1ae34fa
+28 -7
View File
@@ -1,14 +1,26 @@
#!/usr/bin/env bash
# Usage: ./scripts/fetch-year.sh YEAR
# Usage: ./scripts/fetch-year.sh YEAR [--reverse]
# Fetches sequentially; prints JSON responses to stdout and errors to stderr.
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: $0 YEAR" >&2
reverse=false
year=
for arg in "$@"; do
case "$arg" in
--reverse) reverse=true ;;
*)
if [[ -n $year ]]; then
echo "Usage: $0 YEAR [--reverse]" >&2
exit 1
fi
year=$arg
;;
esac
done
if [[ -z $year ]]; then
echo "Usage: $0 YEAR [--reverse]" >&2
exit 1
fi
year=$1
if [[ ! $year =~ ^[0-9]{4}$ || $year == 0000 ]]; then
echo "YEAR must be a four-digit year from 0001 to 9999." >&2
exit 1
@@ -66,8 +78,17 @@ fi
# Generate dates without relying on platform-specific date command options.
status=0
for (( month = 1; month <= 12; month++ )); do
for (( day = 1; day <= days_in_month[month - 1]; day++ )); do
for (( month_index = 0; month_index < 12; month_index++ )); do
month=$((month_index + 1))
if [[ $reverse == true ]]; then
month=$((12 - month_index))
fi
days=${days_in_month[month - 1]}
for (( day_index = 0; day_index < days; day_index++ )); do
day=$((day_index + 1))
if [[ $reverse == true ]]; then
day=$((days - day_index))
fi
printf -v date '%s-%02d-%02d' "$year" "$month" "$day"
if ! curl --fail --silent --show-error -X GET \
"http://localhost:4101/api/price/day/$date" \