File: get_bank_registry_lt.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 (38 lines) | stat: -rw-r--r-- 1,153 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
#!/usr/bin/env python
import json

import requests
from bs4 import BeautifulSoup


URL = "https://www.lb.lt/zinynai/branches.aspx"


def process():
    registry = []
    xml_content = requests.get(URL).text
    soup = BeautifulSoup(xml_content, "xml")
    participants = soup.find_all("participant")  # participants are primary bank names in LB list

    for participant in participants:
        branches = participant.find_all("branch")
        for index, branch in enumerate(branches):
            try:
                entry = {
                    "country_code": "LT",
                    "bic": participant.find("BIC").get_text(),
                    "bank_code": branch.find("FICODE").get_text(),
                    "name": branch.find("NAME").get_text(),
                    "short_name": participant.find("NAME").get_text(),
                    "primary": index == 0,
                }
                registry.append(entry)
            except AttributeError:
                pass

    return registry


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