From 29e1ae34fa84ca3c6e52e8a9ab40d7ac1abd0189 Mon Sep 17 00:00:00 2001 From: Per Magnus Petersen Date: Wed, 30 Sep 2026 16:31:27 +0200 Subject: [PATCH] Add reverse date order to fetch-year script --- scripts/fetch-year.sh | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/fetch-year.sh b/scripts/fetch-year.sh index c79d1b6..17ff29b 100755 --- a/scripts/fetch-year.sh +++ b/scripts/fetch-year.sh @@ -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" \