Skip to content

Instantly share code, notes, and snippets.

@pavelschon
Created April 24, 2022 15:52
Show Gist options
  • Save pavelschon/c23bf6c0c5c910625f775fb5cd51999c to your computer and use it in GitHub Desktop.
Save pavelschon/c23bf6c0c5c910625f775fb5cd51999c to your computer and use it in GitHub Desktop.
Import ČNB rates (denní kurz)
#!/usr/bin/env python3
import csv
import codecs
import requests
class CNB:
'''CNB CSV dialect'''
delimiter = '|'
fieldnames = ( 'country', 'currency', 'quantity', 'code', 'rate' )
url = 'https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.txt'
if __name__ == '__main__':
response = requests.get(CNB.url, stream=True)
response.raise_for_status()
iter_decoded = codecs.iterdecode(response.raw, 'utf-8')
csv_reader = csv.DictReader(iter_decoded, fieldnames=CNB.fieldnames, dialect=CNB)
# skip first two lines
next(csv_reader)
next(csv_reader)
for row in csv_reader:
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment