Non-Android

Hacky New Year

Sometimes all we need is a dirty hack. I’m not talking about production apps, but personal projects where properly engineering things gains me little value. This article has no content or techniques specific to Android, but there will be a follow-up post which does.

Background

At the time of writing, I am working under a contract which pays in US dollars. I want to convert from USD to GBP when the exchange rates are most favourable. So I need to monitor the currency exchange rates.

In my home office, I have a LaMetric Time connected clock. It seemed sensible to try and use it to display exchange rates. This is not a sponsored post. I purchased the device at full price a while back, and it just seemed an obvious choice for this.

There are various third-party apps for the Time to display currency rates, but they either didn’t work or didn’t meet my requirements. I won’t go into the details of the calculations I wanted to do. But I wanted an idea of any gains or losses I might face by converting at the current exchange rate. Rather than simply exposing the raw rate.

The LaMetric APIs might enable me to develop my own app. But this seemed a steep learning curve, and I’d need to develop a backend to support it. This seemed a lot of work. That’s when I discovered a couple of little tricks that enabled the solution that I now use.

Google Finance API

While I was investigating various APIs for obtaining exchange rates, I came across the Google Finance API. Initially, this didn’t look too promising until I discovered its Google Sheets integration. I was able to get the current USD to GBP exchange rate by adding a function call to a cell in a Google Sheets spreadsheet:

= GOOGLEFINANCE("USDGBP")

This isn’t a one-shot retrieval, it will periodically update the value in the cell. This means I have a cell which has a live exchange rate value, and any calculations using it will update automatically.

I was now able to perform my calculations in Google sheets.

Displaying The Data

It now seemed a relatively simple task to get this to display on the Time. LaMetric has an app which will display the value of a cell in a Google sheet on the Time. Unfortunately, it wasn’t as straightforward as it might appear. The app required the spreadsheet to have public visibility. That was not something that I was comfortable with.

I found another solution, though. There is another app which integrates with IFTTT. Once again, this is not a sponsored post, this is what I genuinely use. There is also a Google Sheets integration for IFTTT and this requires OAuth with my Google account. The IFTTT sheets integration is therefore able to read cells from a private sheet, which is precisely what I needed.

I was able to quickly set up an IFTTT applet which periodically reads the value from a spreadsheet cell, and updates the Time app. This, in turn, updates the display on the Time device.

Conclusion

I now have various calculations cycling on my Time display which provide me with loss and gain information. This enables me to better judge the optimum time to transfer from USD to GBP.

That said, this solution will not scale at all. However for one-off, customised use-cases such as this it does exactly what I need without over-engineering.

In the next article we’ll focus more an an Android-specific use-case.

© 2021 – 2020, Mark Allison. All rights reserved.

Copyright © 2021 Styling Android. All Rights Reserved.
Information about how to reuse or republish this work may be available at http://blog.stylingandroid.com/license-information.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.