Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2025-05-05 16:39:51 +0200
committerArthur de Jong <arthur@arthurdejong.org>2025-05-05 16:59:03 +0200
commit37320ea1b38f3b3356a903af470d65b072cd7691 (patch)
tree3d75b55b428fdd60815c574e588f12f4d5134d09
parent98b4fa0d9c3bdcf365c7825a6e754ec3c0a14992 (diff)
Fix the downloading of Belgian bank identifiers
The site switched from XLS to XLSX files.
-rwxr-xr-xupdate/be_banks.py15
-rw-r--r--update/requirements.txt1
2 files changed, 8 insertions, 8 deletions
diff --git a/update/be_banks.py b/update/be_banks.py
index 7cb6f31..eef7bf7 100755
--- a/update/be_banks.py
+++ b/update/be_banks.py
@@ -3,7 +3,7 @@
# update/be_banks.py - script to download Bank list from Belgian National Bank
#
-# Copyright (C) 2018-2019 Arthur de Jong
+# Copyright (C) 2018-2025 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -23,15 +23,16 @@
"""This script downloads the list of banks with bank codes as used in the
IBAN and BIC codes as published by the Belgian National Bank."""
+import io
import os.path
+import openpyxl
import requests
-import xlrd
# The location of the XLS version of the bank identification codes. Also see
# https://www.nbb.be/en/payment-systems/payment-standards/bank-identification-codes
-download_url = 'https://www.nbb.be/doc/be/be/protocol/current_codes.xls'
+download_url = 'https://www.nbb.be/doc/be/be/protocol/current_codes.xlsx'
# List of values that refer to non-existing, reserved or otherwise not-
@@ -60,7 +61,7 @@ def clean(value):
def get_values(sheet):
"""Return values (from, to, bic, bank_name) from the worksheet."""
- rows = sheet.get_rows()
+ rows = sheet.iter_rows()
# skip first two rows
try:
next(rows)
@@ -79,9 +80,9 @@ def get_values(sheet):
if __name__ == '__main__':
response = requests.get(download_url, timeout=30)
response.raise_for_status()
- workbook = xlrd.open_workbook(file_contents=response.content)
- sheet = workbook.sheet_by_index(0)
- version = sheet.cell(0, 0).value
+ workbook = openpyxl.load_workbook(io.BytesIO(response.content), read_only=True)
+ sheet = workbook.worksheets[0]
+ version = sheet.cell(1, 1).value
print('# generated from %s downloaded from' %
os.path.basename(download_url))
print('# %s' % download_url)
diff --git a/update/requirements.txt b/update/requirements.txt
index b51c684..7f2fd1e 100644
--- a/update/requirements.txt
+++ b/update/requirements.txt
@@ -1,4 +1,3 @@
lxml
openpyxl
requests
-xlrd