← posts

Automated spending tracking

I've always had a problem with tracking my spending. I used to use a "finance tracker" app, which allows me to enter transactions I've made. Unfortunately, I find it a bit of a hassle to use, and occasionally whenever I'm in a rush, I might forget to record certain purchases.

I could use credit card PDF statements at the end of each month and parse it out, but the problem is, I wouldn't know the "running total" before the statement is ready.

The Idea

Whenever possible, I use Apple Pay to, well, pay for things. It would usually send me notifications for payments that went through. I started to think if I can somehow capture these notifications and send it somewhere, maybe some kind of script, so that I can automatically record transactions. I don't think there's a way to fetch the notifications (unlike on Android), so I'd have to think of something else.

The next best idea I have is to take screenshots of the Apple Wallet transactions list, and get a script to parse them.

For example:

Example Apple Wallet transactions list

I'd send the screenshots somewhere, and my script would perform OCR to extract the text. Then, use some kind of pattern matching to parse name of shop, date, time, and amount.

I would then be able to save them into a CSV file for further processing.

Of course, there's still some effort needed to actually take the screenshots, but I figure it's much better than having to manually record down the transactions one at a time.

The Python script(s) is at this GitHub repo branch here. It's part of a larger project of finance tracking and dashboarding I worked on with a friend. There's still some finishing touches I'd have to make before merging with main branch, at time of writing this.

Additional Feature: Parsing Email Notifications

Aside from using my credit card, I often use PayNow QR codes to pay for things. My bank would send me email notifications for these payments, for example:

Example PayNow transaction emails

This is an additional form of input to complement the Apple Wallet screenshots.

Example Setup

Here's an example setup I've tried.

I setup a new Gmail account, that would store the Apple Pay screenshots. Once every few days, I open up my Apple Wallet app, take a screenshot, and email it to the Gmail account as an attachment. Additionally, I've configured a forwarding rule on my primary email account, to send the PayNow QR transactions to the special Gmail account.

One of the scripts I have would retrieve the emails from that account, and download the images to a local directory. Another script can be used to scan the images, parse the transactions, and output a CSV file.

Here's a visualization of the system:

Diagram for payments parser system