I need to read a swift message MT103 like this:
{1:F01AAAAGRA0AXXX0057000289}
{2:O1030919010321BBBBGRA0AXXX00570001710103210920N}
{3:{108:MT103 003 OF 045}{121:c8b66b47-2bd9-48fe-be90-93c2096f27d2}}
{4:
:20:5387354
:23B:CRED
:23E:PHOB/20.527.19.60
:32A:000526USD1101,50
:33B:USD1121,50
:50K:FRANZ HOLZAPFEL GMBH
VIENNA
:52A:BKAUATWW
:59:723491524
C. KLEIN
BLOEMENGRACHT 15
AMSTERDAM
:71A:SHA
:71F:USD10,
:71F:USD10,
:72:/INS/CHASUS33
-}
{5:{MAC:75D138E4}{CHK:DE1B0D71FA96}}
Into a structured table using python (or R).
Has someone faced the same problem in the past?
Thank for the help.
Have you seen this PyPi library? According to the flyer it promises you can read in a MT103 file and parses it into a native Python object. It seems like it's not going to be much easier than this? [EDIT]
In the following code example I tried the mt103 library for myself using PyPi (sudo pip install mt103
). I did not however have a valid mt103 example file at hand, so I got some dummy data instead. This seemed to work a little, except for my file not having a bank_operation_code. Do note however that I did NOT get an error when providing a valid but otherwise incorrect string. The library does not check for mt103 validity. It shows when inspecting the object after initialization only to find that the text and header attributes are empty.
from mt103 import MT103
with open('mtfile', 'r') as myfile:
mt103=myfile.read().replace('\n', '')
mt_text = MT103(mt103)
print("basic header: {}, bank op code: {}, complete message: {}".format(
mt_text.basic_header,
mt_text.text.bank_operation_code,
mt_text.raw
))
After you have the object AND it is valid you should be able to figure out how to make it into a table like specified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With