''' Przykładowe adresy
http://api.nbp.pl/api/exchangerates/tables/A
http://api.nbp.pl/api/exchangerates/tables/B
http://api.nbp.pl/api/exchangerates/tables/C
http://api.nbp.pl/api/exchangerates/tables/A/2015-05-05

http://api.nbp.pl/api/exchangerates/tables/A?format=xml
http://api.nbp.pl/api/exchangerates/tables/A?format=json

'''

# na zmienną wrzucam to, co pobrałem z serwisu NBP
json = [{"table": "A", "no": "221/A/NBP/2019", "effectiveDate": "2019-11-15",
         "rates": [{"currency": "bat (Tajlandia)", "code": "THB", "mid": 0.1285},
                   {"currency": "dolar amerykański", "code": "USD", "mid": 3.8848},
                   {"currency": "dolar australijski", "code": "AUD", "mid": 2.6370},
                   {"currency": "dolar Hongkongu", "code": "HKD", "mid": 0.4964},
                   {"currency": "dolar kanadyjski", "code": "CAD", "mid": 2.9333},
                   {"currency": "dolar nowozelandzki", "code": "NZD", "mid": 2.4788},
                   {"currency": "dolar singapurski", "code": "SGD", "mid": 2.8527},
                   {"currency": "euro", "code": "EUR", "mid": 4.2807},
                   {"currency": "forint (Węgry)", "code": "HUF", "mid": 0.012793},
                   {"currency": "frank szwajcarski", "code": "CHF", "mid": 3.9206},
                   {"currency": "funt szterling", "code": "GBP", "mid": 5.0014},
                   {"currency": "hrywna (Ukraina)", "code": "UAH", "mid": 0.1605},
                   {"currency": "jen (Japonia)", "code": "JPY", "mid": 0.035744},
                   {"currency": "korona czeska", "code": "CZK", "mid": 0.1673},
                   {"currency": "korona duńska", "code": "DKK", "mid": 0.5729},
                   {"currency": "korona islandzka", "code": "ISK", "mid": 0.031499},
                   {"currency": "korona norweska", "code": "NOK", "mid": 0.4245},
                   {"currency": "korona szwedzka", "code": "SEK", "mid": 0.4015},
                   {"currency": "kuna (Chorwacja)", "code": "HRK", "mid": 0.5753},
                   {"currency": "lej rumuński", "code": "RON", "mid": 0.8976},
                   {"currency": "lew (Bułgaria)", "code": "BGN", "mid": 2.1887},
                   {"currency": "lira turecka", "code": "TRY", "mid": 0.6743},
                   {"currency": "nowy izraelski szekel", "code": "ILS", "mid": 1.1159},
                   {"currency": "peso chilijskie", "code": "CLP", "mid": 0.004835},
                   {"currency": "peso filipińskie", "code": "PHP", "mid": 0.0767},
                   {"currency": "peso meksykańskie", "code": "MXN", "mid": 0.2014},
                   {"currency": "rand (Republika Południowej Afryki)", "code": "ZAR", "mid": 0.2627},
                   {"currency": "real (Brazylia)", "code": "BRL", "mid": 0.9259},
                   {"currency": "ringgit (Malezja)", "code": "MYR", "mid": 0.9354},
                   {"currency": "rubel rosyjski", "code": "RUB", "mid": 0.0608},
                   {"currency": "rupia indonezyjska", "code": "IDR", "mid": 0.00027605},
                   {"currency": "rupia indyjska", "code": "INR", "mid": 0.054128},
                   {"currency": "won południowokoreański", "code": "KRW", "mid": 0.003333},
                   {"currency": "yuan renminbi (Chiny)", "code": "CNY", "mid": 0.5541},
                   {"currency": "SDR (MFW)", "code": "XDR", "mid": 5.3415}]}]

# to jest lista jednoelementowa
print(type(json), len(json))

# pojedyncze tabele są słownikami
tabela = json[0]

print(type(tabela), len(tabela))

# Podstawowe informacje
print(tabela['effectiveDate'], tabela['no'])

# Pod kluczem 'rates' znajduje się lista 35 walut
rates = tabela['rates']
print(type(rates), len(rates))

# każda waluta to 3-elemetowy słownik
for waluta in rates:
    print(waluta)
print()

for waluta in rates:
    kod = waluta['code']
    nazwa = waluta['currency']
    kurs = waluta['mid']
    print(f'{kod} {"("+nazwa+")":40} : {kurs:<8}')
