Skip to content

Instantly share code, notes, and snippets.

@lcguida
Created September 7, 2018 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcguida/1397b5524aff022d28f374b21a65e4c9 to your computer and use it in GitHub Desktop.
Save lcguida/1397b5524aff022d28f374b21a65e4c9 to your computer and use it in GitHub Desktop.
BitBar script to show BRL currency
#!/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