3

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.

henrywongkk
  • 1,840
  • 3
  • 17
  • 26
Luca Pedretti
  • 31
  • 1
  • 2

1 Answers1

3

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.

JustLudo
  • 1,690
  • 12
  • 29
  • Yes I've read it. I'm finding some difficulties in passing the swift message to th function MT103. I don't know if you've tried, for sure i'm doing a stupid error but i cannot make it work! – Luca Pedretti Jan 28 '19 at 15:15
  • I have not tried it myself, but perhaps it is good to a detailed issue on what you tried and what you encountered? – JustLudo Jan 28 '19 at 15:24
  • I am finding difficulties in passing a string to MT103 because if I put the message that I wrote above just in one line (so deleting new lines) I am able to save it as string object but MT103 is not working, else I'm not able to save it as string because of new lines. – Luca Pedretti Jan 28 '19 at 16:49
  • I added some tests I did for myself. Hopefully this will help. – JustLudo Jan 29 '19 at 10:27