diff options
author | petr.prikryl <petr.prikryl@olc.cz> | 2022-06-08 17:14:40 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2022-08-14 15:40:21 +0200 |
commit | c5595c7e80277bbf2102f293c1f4fbcec07f7101 (patch) | |
tree | 2233e446abe23cf33111d87881885221a0d5c7bd /update | |
parent | 4d4a0b35dd8db8a4ddba469dc2cb646f1f877785 (diff) |
Add Czech bank account numbers
Closes https://github.com/arthurdejong/python-stdnum/issues/295
Closes https://github.com/arthurdejong/python-stdnum/pull/296
Diffstat (limited to 'update')
-rwxr-xr-x | update/cz_banks.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/update/cz_banks.py b/update/cz_banks.py new file mode 100755 index 0000000..fd7c976 --- /dev/null +++ b/update/cz_banks.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# coding: utf-8 + +# update/cz_banks.py - script to download Bank list from Czech National Bank +# +# Copyright (C) 2022 Petr Přikryl +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 USA + +"""This script downloads the list of banks with bank codes as used in the +IBAN and BIC codes as published by the Czech National Bank.""" + +import csv +import os.path +from io import StringIO + +import requests + + +# The location of the CSV version of the bank identification codes. Also see +# https://www.cnb.cz/cs/platebni-styk/ucty-kody-bank/ +download_url = 'https://www.cnb.cz/cs/platebni-styk/.galleries/ucty_kody_bank/download/kody_bank_CR.csv' + + +def get_values(csv_reader): + """Return values (bank_number, bic, bank_name, certis) from the CSV.""" + # skip first row (header) + try: + next(csv_reader) + except StopIteration: + pass # ignore empty CSV + + for row in csv_reader: + yield row[0], row[2], row[1], row[3] == 'A' + + +if __name__ == '__main__': + response = requests.get(download_url) + response.raise_for_status() + csv_reader = csv.reader(StringIO(response.content.decode('utf-8')), delimiter=';') + print('# generated from %s downloaded from' % os.path.basename(download_url)) + print('# %s' % download_url) + for bank_number, bic, bank, certis in get_values(csv_reader): + info = '%s' % bank_number + if bic: + info += ' bic="%s"' % bic + if bank: + info += ' bank="%s"' % bank + if certis: + info += ' certis="%s"' % certis + print(info) |