Created
May 15, 2018 10:23
-
-
Save ArtBIT/1263bc04980516cb3a9d8679e794bd77 to your computer and use it in GitHub Desktop.
Kurna lista na dan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATE=$1 | |
CURRENCY=${2:-usd} | |
KURS=${3:-sre} | |
FORMAT="json" | |
API_KEY="YOUR_API_KEY_HERE" # https://www.kursna-lista.info/moj-nalog/api-podesavanja | |
API_ENDPOINT="https://api.kursna-lista.info/$API_KEY/kl_na_dan/$DATE/$FORMAT" | |
CACHE="$HOME/.kursna_lista/$DATE.$CURRENCY.$KURS" | |
if [ ! -f "$CACHE" ]; then | |
API_RESULT=$(curl $API_ENDPOINT 2>/dev/null) | |
VALUE=$(echo $API_RESULT | jq ".result.$CURRENCY.$KURS" | sed 's/"//g') | |
re='^[0-9.]+$' | |
if [[ "$VALUE" =~ $re ]]; then | |
echo $VALUE > "$CACHE"; | |
else | |
echo "Invalid value for date $DATE" | |
echo "$API_ENDPOINT" | |
exit | |
fi | |
fi | |
VALUE=$(cat "$CACHE") | |
echo $VALUE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
kursna-lista.sh dd.mm.yyyy [usd | eur | gbp | rub ...] [sre | kup | pro]
Example:
kursna-lista.sh 11.11.2011 usd sre