Skip to content

Commit

Permalink
initial stages of camt tools
Browse files Browse the repository at this point in the history
  • Loading branch information
phoughton committed Aug 12, 2024
1 parent e35ba6d commit 1cf5b3f
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,5 @@ pain/
pyiso20022/

temp/

*.xlsx
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pytest
xsdata[cli,lxml,soap]
pandas
openpyxl
2 changes: 1 addition & 1 deletion tests/parse_camt053_msgs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.mark.parametrize("expected_acc_id", [
("DD01100056869")
])
def test_parse_camt052_001_02(expected_acc_id):
def test_parse_camt053_001_02(expected_acc_id):

parser = XmlParser()

Expand Down
41 changes: 41 additions & 0 deletions tools/camt053_to_excel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from lxml import etree
import pandas as pd


def modify_key(key, translate=True):
return key.split('}')[-1]


def parse_element(element, parent_name=''):
data_dict = {}
for child in element:
child_name = f"{parent_name}_{child.tag}" if parent_name else child.tag

if len(child):
data_dict.update(parse_element(child, child_name))
else:
data_dict[child_name] = child.text

modified_dict = {modify_key(k): v for k, v in data_dict.items()}

return modified_dict


def camt053_to_excel(xml_fname, excel_fname):
with open(xml_fname, "rb") as xml_file:
xml_data = xml_file.read()

root = etree.fromstring(xml_data)
data = []
elements = root.xpath('//*[local-name()="Ntry"]')

for record in elements:
record_data = parse_element(record)
data.append(record_data)

df = pd.DataFrame(data)

df.to_excel(excel_fname, index=False)


camt053_to_excel("example_files/gs_camt/camt053_001_02.xml", "camt053_001_02.xlsx")
78 changes: 78 additions & 0 deletions tools/lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
mnemonic_lookup = {
'Bk': 'Bank',
'Br': 'Bearer',
'Cd': 'Code',
'Dt': 'Date',
'FI': 'FinancialInstitution',
'Fr': 'From',
'Id': 'Identification',
'Nb': 'Number',
'Nm': 'Name',
'Of': 'Of',
'Tm': 'Time',
'To': 'To',
'Tp': 'Type',
'Tx': 'Transaction',
'Adr': 'Address',
'Agt': 'Agent',
'Amt': 'Amount',
'Biz': 'Business',
'Ccy': 'Currency',
'Cdt': 'Credit',
'Clr': 'Clearing',
'Cre': 'Creation',
'Def': 'Definition',
'End': 'End',
'Fin': 'Financial',
'For': 'For',
'Grp': 'Group',
'Hdr': 'Header',
'Idr': 'Identifier',
'Inf': 'Information',
'Msg': 'Message',
'Mtd': 'Method',
'Nxt': 'Next',
'Org': 'Organisation',
'Pmt': 'Payment',
'Pst': 'Post',
'Pty': 'Party',
'Rmt': 'Remittance',
'Sum': 'Sum',
'Svc': 'Service',
'Sys': 'System',
'Trf': 'Transfer',
'Twn': 'Town',
'Txs': 'Transactions',
'Acct': 'Account',
'Bldg': 'Building',
'Cdtr': 'Creditor',
'Chrg': 'Charge',
'Ctgy': 'Category',
'Ctrl': 'Control',
'Ctry': 'Country',
'Dbtr': 'Debtor',
'Intr': 'Inter',
'Othr': 'Other',
'Prty': 'Priority',
'Pstl': 'Postal',
'Purp': 'Purpose',
'Reqd': 'Requested',
'Rltd': 'Related',
'Root': 'Root',
'Strt': 'Street',
'UETR': 'UETR',
'BICFI': 'BICFI',
'Chrgs': 'Charges',
'Cstmr': 'Customer',
'Exctn': 'Execution',
'Initg': 'Initiating',
'Initn': 'Initiation',
'Instd': 'Instructed',
'Instg': 'Instructing',
'Instn': 'Institution',
'Instr': 'Instruction',
'Prtry': 'Proprietary',
'Sttlm': 'Settlement',
'Ultmt': 'Ultimate',
'Ustrd': 'Unstructured'
}

0 comments on commit 1cf5b3f

Please sign in to comment.