Screenshot of the exchangeRates.py output

Simple Exchange Rates Script

As a Norwegian living in France and working at CERN, on the Swiss side of the border, I have to deal with all three currencies almost on a daily basis. So, as one does, I wrote a small script that pulls the latest exchange rates for me.

I recently discovered the exchange rate API at fixer.io, which caches the rates from the European Central Bank. In addition I have a bit of crypto currency, and I like to check what those coins are worth too.

For all of this, I wrote a short Python script that pulls information for these APIs – although it ignores the crypto currencies if you don’t specify any. It then calculates the exchange matrix and displays it in a table in the terminal as seen in the image above. You can choose the currencies for each column and row in the script, and optionally which row or column to highlight.

The script can be called with or without a date specified in ISO format, i.e. YYYY-MM-DD. If one is not specified, it will use today’s date. The table will list the actual date of the exchange rate if there is none available for the specified date. The European Central Bank only provides rates for week days, and they do the calculations at 14:15 CET. They are available in the fixer.io API some time after 15:00 CET.

If you find this script interesting, check it out on GitHub Gist as exchangeRates.py.

Featured Posts

    Leave a Reply

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