3 Commits
Author SHA1 Message Date
magnus 29e1ae34fa Add reverse date order to fetch-year script
build / build (push) Successful in 3m50s
2026-09-30 16:31:27 +02:00
magnus 8653076c97 Merge branch 'day-history' 2026-09-30 08:54:04 +02:00
magnus 790e24ee06 Merge pull request 'Add daily BTC/USD endpoint with historical caching and Swagger UI' (#2) from day-history into master
build / build (push) Successful in 3m40s
Reviewed-on: #2
2026-09-30 05:50:36 +00:00
+28 -7
View File
@@ -1,14 +1,26 @@
#!/usr/bin/env bash #!/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. # Fetches sequentially; prints JSON responses to stdout and errors to stderr.
set -euo pipefail set -euo pipefail
if [[ $# -ne 1 ]]; then reverse=false
echo "Usage: $0 YEAR" >&2 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 exit 1
fi fi
year=$1
if [[ ! $year =~ ^[0-9]{4}$ || $year == 0000 ]]; then if [[ ! $year =~ ^[0-9]{4}$ || $year == 0000 ]]; then
echo "YEAR must be a four-digit year from 0001 to 9999." >&2 echo "YEAR must be a four-digit year from 0001 to 9999." >&2
exit 1 exit 1
@@ -66,8 +78,17 @@ fi
# Generate dates without relying on platform-specific date command options. # Generate dates without relying on platform-specific date command options.
status=0 status=0
for (( month = 1; month <= 12; month++ )); do for (( month_index = 0; month_index < 12; month_index++ )); do
for (( day = 1; day <= days_in_month[month - 1]; day++ )); 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" printf -v date '%s-%02d-%02d' "$year" "$month" "$day"
if ! curl --fail --silent --show-error -X GET \ if ! curl --fail --silent --show-error -X GET \
"http://localhost:4101/api/price/day/$date" \ "http://localhost:4101/api/price/day/$date" \