Skip to content

Instantly share code, notes, and snippets.

@mguzelevich
Created October 1, 2020 10:38
Show Gist options
  • Save mguzelevich/340b830e8e1443451d933e95bd321f61 to your computer and use it in GitHub Desktop.
Save mguzelevich/340b830e8e1443451d933e95bd321f61 to your computer and use it in GitHub Desktop.
nbrb.by rates fetcher
.PHONY: run test clean
help:
@echo "make currencyId=145 currency-rates"
years = $(shell seq 1995 1 2020)
currencyId = 145 # USD
currencies:
curl "https://www.nbrb.by/api/exrates/currencies" | jq '.' > nbrb.currencies.json
echo -e "Cur_ID,Cur_ParentID,Cur_Code,Cur_Abbreviation,Cur_Name,Cur_Name_Bel,Cur_Name_Eng,Cur_QuotName,Cur_QuotName_Bel,Cur_QuotName_Eng,Cur_NameMulti,Cur_Name_BelMulti,Cur_Name_EngMulti,Cur_Scale,Cur_Periodicity,Cur_DateStart,Cur_DateEnd" > nbrb.currencies.csv
cat nbrb.currencies.json | jq -r '.[] | "\(.Cur_ID),\(.Cur_ParentID),\(.Cur_Code),\(.Cur_Abbreviation),\(.Cur_Name),\(.Cur_Name_Bel),\(.Cur_Name_Eng),\(.Cur_QuotName),\(.Cur_QuotName_Bel),\(.Cur_QuotName_Eng),\(.Cur_NameMulti),\(.Cur_Name_BelMulti),\(.Cur_Name_EngMulti),\(.Cur_Scale),\(.Cur_Periodicity),\(.Cur_DateStart),\(.Cur_DateEnd)"' >> nbrb.currencies.csv
date:
curl "https://www.nbrb.by/api/exrates/rates/USD?parammode=2&ondate=2019-07-10" | jq '.'
url = https://www.nbrb.by/api/exrates/rates/dynamics/$(currencyId)
currency-rates:
$(foreach year,$(years),sleep 5; curl "${url}?startdate=$(year)-01-01&enddate=$(year)-12-31" | jq '.' > nbrb.$(currencyId).$(year).json;)
echo -e "date,currency,rate" > nbrb.$(currencyId).csv
cat nbrb.$(currencyId).*.json | jq -r '.[] | "\(.Date),\(.Cur_ID),\(.Cur_OfficialRate)"' >> nbrb.$(currencyId).csv
currencies = 145 292 # USD EUR
all-rates:
$(foreach currency,$(currencies),make currencyId=$(currency) currency-rates;)
db = currencies.s3db
import currencies all-rates:
rm -f $(db)
echo -e ".mode csv\n.import nbrb.currencies.csv currencies" | sqlite3 $(db)
$(foreach currency,$(currencies),echo -e ".mode csv\n.import nbrb.$(currency).csv rates" | sqlite3 $(db);)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment