I wanted to learn the fundamentals of Go over a weekend and thought what better way to do it than to find a cool project to work on. Living pretty close to a Wetherspoons, it’s a pub I frequent pretty often. Also, being a student at University I use Trainline to buy my tickets, as the ticket operator with the nicest UX by a mile.
To design the project; I started considering the best way to harvest the data and initially planned to use Gmail’s APIs to harvest mail from my own inbox, but decided in the end that IMAP would be a better option as it works across pretty much every mail provider used in the last 20 years.
This is where eazye came in as a nice way to get emails from IMAP, it didn’t support custom commands, however, so I added the ability to add custom IMAP commands to it, which means you can do custom mail searches such as FROM "[email protected]"
.
Then comes the scraping, which was bit inconvenient as mail layouts change over time - but both now work for all the layouts of the Trainline and Wetherspoons I’ve found, all the receipt items are then stored and passed back to be compared later on.
Next up it was the Monzo integration, and after getting a list of transactions and narrowing them down by the merchant’s names we get a list of all the possible matches. Then it’s time to compare them to look for matches, if one is found that falls within the acceptable sent time (Wetherspoons 1.5 hours, Trainline 3 hours) a PUT
request gets sent to Monzo with the details they’ll need to generate a receipt.
I considered integrating this with Starling Bank, as I’ve previously used them as my main current account, but unfortunately, they don’t offer a developer-facing receipts API.
I had a go at implementing it as custom text in the transaction information (in the style shown above) but didn’t get a result that I thought was good enough to publish, especially as it wouldn’t handle updates well. The nice thing about Monzo’s implementation is I can generate a receipt ID from the time the email was sent and the retailer’s name, and they’ll recognise this is an update, and not make a second receipt.