Keep an eye on the currencies you choose from your menu bar !
#!/usr/bin/python
# -*- coding: utf-8 -*-
# <xbar.title>Currency Tracker</xbar.title>
# <xbar.version>1.0</xbar.version>
# <xbar.author>Maxime Bertheau</xbar.author>
# <xbar.author.github>maxoumime</xbar.author.github>
# <xbar.desc>Keep an eye on the currencies you choose from your menu bar !</xbar.desc>
# <xbar.image>https://nothingreally.botler.me/bitbar.currency-tracker.png</xbar.image>
import urllib2
import json
# Write here the currencies you want to see
# Base comparaison currency
currFrom = "EUR"
# Array of tracked currencies
currTo = ["CAD", "USD"]
urlParamTo = currTo[0]
if len(currTo) > 1:
urlParamTo = ",".join(currTo)
url = "https://api.exchangeratesapi.io/latest?base=" + currFrom + "&symbols=" + urlParamTo
result = urllib2.urlopen(url).read()
jsonCurr = json.loads(result)
rates = jsonCurr["rates"]
keys = rates.keys()
for key in reversed(keys):
# round down to four decimals
print key + ": " + ("%.4f" % rates[key])
print "---"
print "From: " + currFrom