Created
September 7, 2018 15:53
-
-
Save lcguida/1397b5524aff022d28f374b21a65e4c9 to your computer and use it in GitHub Desktop.
BitBar script to show BRL currency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'json' | |
url = "http://data.fixer.io/api/latest?access_key=${ENV['FIXER_API_KEY']}&symbols=BRL" | |
response = Net::HTTP.get(URI(url)) | |
body = JSON.parse(response) | |
rate = body['rates'] && body['rates']['BRL'] # sometimes I work with ruby 2.2 which doesnt have dig =( | |
if rate | |
puts ("EUR: R$ %.3f" % rate) | |
else | |
puts 'EUR: ---' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment