File: get_bank_registry_hu.py

package info (click to toggle)
python-schwifty 2024.09.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,072 kB
  • sloc: python: 3,057; makefile: 209; sh: 9
file content (44 lines) | stat: -rwxr-xr-x 1,213 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
import json

import pandas


URL = "https://www.mnb.hu/letoltes/sht.xlsx"


def process():
    registry = []
    datas = pandas.read_excel(URL, sheet_name=0, dtype="str")
    datas.fillna("", inplace=True)

    bank_codes = set()
    for row in datas.itertuples(index=False):
        code, bic, name = row[:3]

        # The branch code, which is the remainder of the `code`,  could be used to figure out the
        # correct bank name (including the branch location), but that would require to alter the
        # way banks are being looked up.
        bank_code = code[:3]
        if bank_code in bank_codes:
            continue

        bank_codes.add(bank_code)
        registry.append(
            {
                "country_code": "HU",
                "primary": True,
                "bic": str(bic).upper().replace(" ", ""),
                "bank_code": str(bank_code),
                "name": name,
                "short_name": name,
            }
        )

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


if __name__ == "__main__":
    with open("schwifty/bank_registry/generated_hu.json", "w") as fp:
        json.dump(list(process()), fp, indent=2)