Skip to content

Commit

Permalink
Update swedish bank registry (mdomke#108)
Browse files Browse the repository at this point in the history
* Update script to fetch data from PDF

* Add Dockerfile to generate updated Swedish list

* Update list of Swedish banks
  • Loading branch information
jmfederico authored Nov 22, 2022
1 parent fb6f063 commit 1b58ad4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 25 deletions.
44 changes: 38 additions & 6 deletions schwifty/bank_registry/generated_se.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"country_code": "SE",
"primary": true,
"bic": "AABAFI22",
"bic": "AABASESS",
"bank_code": "230",
"name": "\u00c5landsbanken",
"short_name": "\u00c5landsbanken"
Expand Down Expand Up @@ -63,6 +63,14 @@
"name": "Citibank (filial)",
"short_name": "Citibank (filial)"
},
{
"country_code": "SE",
"primary": true,
"bic": "FEMAMTMT",
"bank_code": "907",
"name": "Ferratum Bank",
"short_name": "Ferratum Bank"
},
{
"country_code": "SE",
"primary": true,
Expand Down Expand Up @@ -98,7 +106,7 @@
{
"country_code": "SE",
"primary": true,
"bic": "DABASESX",
"bic": "MARGSESS",
"bank_code": "923",
"name": "Marginalen Bank",
"short_name": "Marginalen Bank"
Expand Down Expand Up @@ -127,6 +135,14 @@
"name": "Resurs Bank AB",
"short_name": "Resurs Bank AB"
},
{
"country_code": "SE",
"primary": true,
"bic": "SWEDSESS",
"bank_code": "930",
"name": "Swedbank",
"short_name": "Swedbank"
},
{
"country_code": "SE",
"primary": true,
Expand Down Expand Up @@ -178,11 +194,19 @@
{
"country_code": "SE",
"primary": true,
"bic": "SWEDSESS",
"bic": "SPSDSE23",
"bank_code": "957",
"name": "Sparbanken Syd",
"short_name": "Sparbanken Syd"
},
{
"country_code": "SE",
"primary": true,
"bic": "BMPBSESS",
"bank_code": "958",
"name": "AION Bank",
"short_name": "AION Bank"
},
{
"country_code": "SE",
"primary": true,
Expand All @@ -202,10 +226,10 @@
{
"country_code": "SE",
"primary": true,
"bic": "NOFBSES1",
"bic": "NOFBSESS",
"bank_code": "964",
"name": "Nordax Finans AB (publ)",
"short_name": "Nordax Finans AB (publ)"
"name": "Nordax Bank",
"short_name": "Nordax Bank"
},
{
"country_code": "SE",
Expand Down Expand Up @@ -247,6 +271,14 @@
"name": "Ekobanken",
"short_name": "Ekobanken"
},
{
"country_code": "SE",
"primary": true,
"bic": "NOHLSESS",
"bank_code": "975",
"name": "Northmill Bank",
"short_name": "Northmill Bank"
},
{
"country_code": "SE",
"primary": true,
Expand Down
14 changes: 14 additions & 0 deletions scripts/Dockerfile_se
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.10

# How use this Dockerfile to generate the Swedish bank registry:

# docker build -t schwifty_se -f scripts/Dockerfile_se .
# docker run --rm -v `pwd`:/schwifty --workdir /schwifty schwifty_se

RUN apt update -y \
&& apt install -y ghostscript python3-tk libgl1 \
&& rm -rf /var/lib/apt/lists/*

RUN pip install "camelot-py[base]" opencv-python

CMD [ "python", "scripts/get_bank_registry_se.py" ]
40 changes: 21 additions & 19 deletions scripts/get_bank_registry_se.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
#!/usr/bin/env python
import json

import camelot
import pandas


# https://www.swedishbankers.se/fraagor-vi-arbetar-med/betalningar/ny-nordisk-betalningsinfrastruktur/iban-och-svenskt-nationellt-kontonummer/
# https://www.bankinfrastruktur.se/framtidens-betalningsinfrastruktur/iban-och-svenskt-nationellt-kontonummer
URL = (
"https://www.swedishbankers.se/media/4863/"
"kalkylblad-i-iban-och-svenskt-nationellt-kontonummer-2021-02-16.xlsx"
"https://www.bankinfrastruktur.se/media/d1tlidv0/"
"iban-id-och-bic-adress-for-banker-2022-06-23.pdf"
)


def process():
registry = []
registry = {}

datas = pandas.read_excel(URL, skiprows=2, sheet_name=0, dtype=str)
datas.fillna("", inplace=True)
tables = camelot.read_pdf(URL, pages="1,2")
datas = pandas.concat([tables[0].df, tables[1].df], ignore_index=True)

datas.drop(index=datas.index[0], inplace=True)
datas.drop(index=datas.index[0], inplace=True)
datas.fillna("", inplace=True)
datas.sort_values(1, inplace=True)
for row in datas.itertuples(index=False):
bank_code, bic, name = row[:3]
registry.append(
{
"country_code": "SE",
"primary": True,
"bic": str(bic).upper(),
"bank_code": str(bank_code).split(".", 1)[0],
"name": str(name).strip(),
"short_name": str(name).strip(),
}
)
bank_code, bic, name = row[1:4]
registry[str(bank_code).strip()] = {
"country_code": "SE",
"primary": True,
"bic": str(bic).upper(),
"bank_code": str(bank_code).strip(),
"name": str(name).strip(),
"short_name": str(name).strip(),
}

print(f"Fetched {len(registry)} bank records")
return registry
return list(registry.values())


if __name__ == "__main__":
Expand Down

0 comments on commit 1b58ad4

Please sign in to comment.