Tool to swap name and memo in OFX bank transaction files

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

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.
GeekNeck
 
Posts: 25
Joined: Sat Aug 11, 2012 7:26 am

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.
chazzo
 
Posts: 7
Joined: Tue Oct 08, 2019 12:18 pm

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.
GeekNeck
 
Posts: 25
Joined: Sat Aug 11, 2012 7:26 am

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?
crverdusco
 
Posts: 2
Joined: Wed Jun 03, 2020 9:49 am

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.
GeekNeck
 
Posts: 25
Joined: Sat Aug 11, 2012 7:26 am


Return to Tips & Tricks - DO NOT POST QUESTIONS