Skip to content

Instantly share code, notes, and snippets.

@thomaspeitz
Created October 8, 2017 17:11
Show Gist options
  • Save thomaspeitz/7f8185b4499f4ffaec7abf966fe51331 to your computer and use it in GitHub Desktop.
Save thomaspeitz/7f8185b4499f4ffaec7abf966fe51331 to your computer and use it in GitHub Desktop.
crypto-better-touch-bar
#!/usr/local/bin/ruby
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("http://crypto.nerdswords.de/markets/summaries")
resp = Net::HTTP.get_response(uri)
json = JSON.parse(resp.body)
def getSymbol(pairName)
if pairName =~ /usd$/
symbol = '$'
elsif pairName =~ /eur$/
symbol = '€'
else
symbol = '?'
end
end
ARGV.each do |pair|
price = json['result'][pair]['price']['last']
if price < 1
price = (price * 1000).round(0)
price = '.' + price.to_s
symbol = getSymbol(pair)
else
price = (price).round(0)
symbol = getSymbol(pair)
end
percent = (json['result'][pair]['price']['change']['percentage'] * 100).round(1)
puts "#{price}#{symbol} (#{percent}%)"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment