Skip to content

Instantly share code, notes, and snippets.

@fschutte
Created December 23, 2019 11:21
Show Gist options
  • Save fschutte/e714b8be68d468826bbb559a190e04f6 to your computer and use it in GitHub Desktop.
Save fschutte/e714b8be68d468826bbb559a190e04f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# simple python script that reads eiscd file and outputs sortcode,bankid per sortcode for a specific range of banks
import sys
from lxml import etree
if len(sys.argv) != 2:
print("Please supply one argument, namely the eiscd file")
sys.exit()
else:
eiscdfile = sys.argv[1]
bank_ids = ['0006', '0033']
csv = sorted([f"{office.attrib['SortCode']},{bank.attrib['BankCode']}"
for event, bank in etree.iterparse(eiscdfile, tag="{http://www.bacs.co.uk/schemas}Bank")
if bank.attrib['BankCode'] in bank_ids
for office in bank
if office.tag == '{http://www.bacs.co.uk/schemas}BankOffices'
])
print(*csv, sep="\n")
# eiscd file is something like this:
#
# <BACSDocument xmlns="http://www.bacs.co.uk/schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bacs.co.uk/schemas Extended_ISCD_Extract_Schema.xsd">
# <Data>
# <ISCDDocument>
# <Version>1.0</Version>
# <ProcessingDate>2019-07-15</ProcessingDate>
# <Created>2019-07-12</Created>
# <Bank BankCode="0944">
# <SupervisoryBody>A</SupervisoryBody>
# <AbbreviatedBankName>1ST CLASS CREDIT UN</AbbreviatedBankName>
# <BankName>1ST CLASS CREDIT UNION LIMITED</BankName>
# <BankOffices SortCode="608326" BicBank="" BicBranch="" Suffix="00">
# <BankOfficeTitle>1st Class Credit Union Ltd</BankOfficeTitle>
# <BankOfficeType>M</BankOfficeType>
# <DateLastChanged>2017-04-11</DateLastChanged>
# <PrintIndicator>0</PrintIndicator>
# <Address>
# output is something like this:
# 010004,0006
# 010008,0006
# 010013,0006
# 010039,0006
# ..
# ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment