09 Nov 2015
Personal Finance with Microservices
Personal finance is an interesting topic. Everyone has their own ideal ways of managing personal finances. Being too lazy to enter CSV file to a Numbers sheet, I went ahead and wrote a micro service to hook up expenses into a Google sheet.
I am not a big fan of these application due to below reasons -
- Not accessible enough
- Budgets - Arrrrr, I hate budgets.
- Unnecessary analytics (how much money spent against earned! I don’t want to know how broke I am with a chart)
- Currency conversion (since I end up traveling, I need multiple currency support)
- Crappy UI (biggest turn off)
I know that I am ranting a bit but it’s personal finance
Then I met Daily Costs, an iPhone app that can be used to note costs easily. Beer , 320, Coffee 250 got it. It was all easier to collect the expenses now. Better yet, I could export all that data into a CSV file.
What I was missing now was some analytics on this data. I earlier had a Numbers (an Excel like program for Mac) sheet that did a decent job. Numbers was limited to the local machine and I had to manually enter the data from the CSV to the sheet. This was often messy and I forget to do this all the time.
Since I was looking into Micro services, I thought of building a small service to act on this event and write the CSV generated to a Google Sheet. Sounds simple. I looked back into my usually process of how I would normally handle this scenario.
Sending an email out every weekend from the app was easy. Only require a simple reminder. Catching this email received event was the important part. Then I remembered that there is a cool service called IFFT that can be used for this connection.
I had the sketch of the code in my mind - first I needed to get the CSV file. IFFT can make the request to the web endpoint with a file url of the attachment. Then I downloaded the CSV file from this link.
Next was to convert the CSV to an array structure using the csv-parse module. This would allow me to write the whole CSV to a history transaction sheet on the Google Sheet. Next - I iterated and found the transactions for the current month and inserted them to a separate sheet.
With the help of the nifty little module (google-sheet-npm), I can read the Google Sheet and write. The only problem I had was authenticating into the Google Sheet. I didn’t want to use oAuth, the default mechanism provided to authenticate and authorize 3rd party resources in the web.
Google has an alternative called machine authentication. Google gives you a file based (JSON) token that can be used for authenticating which is associated with a newly generated google account. You need to authorize the google sheet for that google account.
And behold the code:-
Till next time mate,
Dulitha at 15:50