Compare commits

..

1 Commits

Author SHA1 Message Date
5da11394d4
DRY up code, add GBP rates 2025-01-17 14:38:10 -05:00

View File

@ -4,7 +4,7 @@
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
echo "Starting price tracking for $YESTERDAY" >&2
# Function to get and process price data for a currency
# Fetch and process rates for a fiat currency
get_price_data() {
local currency=$1
local data avg open24 last
@ -15,7 +15,6 @@ get_price_data() {
open24=$(echo "$data" | jq -r '.open_24')
last=$(echo "$data" | jq -r '.last')
avg=$(( (${open24%.*} + ${last%.*}) / 2 ))
echo $avg
else
echo "ERROR: Failed to retrieve ${currency} price data" >&2
exit 1
@ -29,7 +28,6 @@ gbp_avg=$(get_price_data "GBP")
# Create JSON
json="{\"EUR\":$eur_avg,\"USD\":$usd_avg,\"GBP\":$gbp_avg}"
echo "Rates: $json" >&2
# PUT in remote storage
response=$(curl -X PUT \