From c5595c7e80277bbf2102f293c1f4fbcec07f7101 Mon Sep 17 00:00:00 2001 From: "petr.prikryl" Date: Wed, 8 Jun 2022 17:14:40 +0200 Subject: Add Czech bank account numbers Closes https://github.com/arthurdejong/python-stdnum/issues/295 Closes https://github.com/arthurdejong/python-stdnum/pull/296 --- update/cz_banks.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 update/cz_banks.py (limited to 'update') 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) -- cgit v1.2.3