Page 1 of 1

Tool to swap name and memo in OFX bank transaction files

PostPosted: Tue Aug 20, 2019 7:58 am
by GeekNeck
OFX files downloaded from my bank annoyingly are merchant-centric and not useful for customers that wish to download transaction data for importation into financial software. The Name of the transaction is the payment method (Debit Card XXXXX), and the Memo is really the merchant (Fred's Flowers).

I have created a tool that rectifies this and it is now a staple of my Hazel workflow. You can see the code at
https://github.com/PaulWaldo/ofx_swapper
It is a lifesaver for me, and I hope that someone else finds it useful.

Re: Tool to swap name and memo in OFX bank transaction files

PostPosted: Wed Nov 06, 2019 7:01 am
by chazzo
Thank you. Late to the party, I know, but this might be useful now that my accounting software has stopped connecting directly to my bank.

More generally, though, thanks for showing me there's life beyond AppleScript. I have zero knowledge of Python, and for a job like this I'd probably use a BBEdit macro. It's fascinating to see how it's not that hard to do it properly.

Re: Tool to swap name and memo in OFX bank transaction files

PostPosted: Wed Nov 06, 2019 11:21 am
by GeekNeck
Hi chazzo, glad this is of some help. The task is fairly simple (conceptually), so many languages could do the trick. I had considered an AWK script, but I just happened to be doing Python recently.

Re: Tool to swap name and memo in OFX bank transaction files

PostPosted: Tue Nov 03, 2020 3:49 pm
by crverdusco
Hi GeekNeck, I was wondering if you thought this could be used to search and replace based on a criteria. I'm trying to set up a hazel rule to edit and OFX. My bank has set up their OFX that they don't show Credits properly so when importing they don't work.
Code: Select all
<STMTTRN>
     <TRNTYPE>DEBIT</TRNTYPE>
     <DTPOSTED>20201029120000.000[0:GMT]</DTPOSTED>
     <TRNAMT>-528.94</TRNAMT>
     <FITID>102920200000000615845</FITID>
     <NAME>APPLE.COM/US ONE APPLE PARK WAY</NAME>
     <MEMO>APPLE.COM/US ONE APPLE PARK WAY Date 10/29/20 030301257022 5732/Withdrawal Adjustment Debit Card - Credit Voucher</MEMO>
</STMTTRN>

I am wondering if I could use python or apple script to search for when it says "Withdrawal adjustment" in the memo and then change the transaction type to Credit and remove the "-" from the transaction amount. I'm not good with the code, do you know if this would be possible? Any direction to look for a way to do this?

Re: Tool to swap name and memo in OFX bank transaction files

PostPosted: Wed Nov 04, 2020 8:44 am
by GeekNeck
crverdusco wrote:I am wondering if I could use python or apple script to search for when it says "Withdrawal adjustment" in the memo and then change the transaction type to Credit and remove the "-" from the transaction amount. I'm not good with the code, do you know if this would be possible? Any direction to look for a way to do this?

I don't think it would be that hard. In the _swap_names_and_memos function, you have access to the individual record elements, so you could add something like this:

Code: Select all
trntype = transaction.find("TRNTYPE")
if "Withdrawal Adjustment" in memo and trntype == "DEBIT":
    trnamt = transaction.find('TRNAMT')
    amount = int(trnamt) * -1
    trnamt.text = str(amount)
    trntype = "CREDIT"


Note, I have not tested this and it may not even compile, but it should be enough to get started. Let me know how it goes.