Skip to content

Instantly share code, notes, and snippets.

@maciejmajewski
Created November 1, 2019 12:07
Show Gist options
  • Save maciejmajewski/3d496eebfd62edf45ca31dc6bf3ab71f to your computer and use it in GitHub Desktop.
Save maciejmajewski/3d496eebfd62edf45ca31dc6bf3ab71f to your computer and use it in GitHub Desktop.
exchange-rates() {
DATE="${1:-}"
FILTER=".[] | {"
FILTER+="table: .table,"
FILTER+="no: .no,"
FILTER+="date: .effectiveDate,"
FILTER+='"EUR": .rates[] | select(.code == "EUR").mid,'
FILTER+='"USD": .rates[] | select(.code == "USD").mid'
FILTER+="}"
URL="http://api.nbp.pl/api/exchangerates/tables/a/${DATE}"
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "${URL}")
if [[ "${STATUS_CODE}" == "404" ]]
then
echo "There is no data for ${DATE}"
else
curl -s "http://api.nbp.pl/api/exchangerates/tables/a/${DATE}" | jq "${FILTER}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment