forked from pretix/pretix-sepadebit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_bic_info.py
32 lines (23 loc) · 920 Bytes
/
update_bic_info.py
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
"""
Updates IBAN→BIC information contained in this module using public sources.
100310001EIS Einlagensicherungsbank 10178Berlin EIS Bank Berlin EIEGDEB1XXX09056711U000000000
"""
import csv
import json
import requests
from bs4 import BeautifulSoup
from collections import defaultdict
map = {}
# Germany
page = requests.get('https://www.bundesbank.de/en/tasks/payment-systems/services/bank-sort-codes/download-bank-sort-codes-626218')
doc = BeautifulSoup(page.text, "lxml")
url = doc.select("a[href*='/blz-aktuell-txt-data.txt']")[0].attrs['href']
data = requests.get(url).text
for line in data.split("\n"):
if not line or line[8] != "1" or line[139] == " ":
continue
map[f'DEXX{line[0:8]}'] = line[139:150]
# Write file
d = json.dumps(map)
with open('pretix_sepadebit/bicdata.py', 'w') as f:
f.write(f'DATA = {d}')