Created
October 8, 2017 17:11
-
-
Save thomaspeitz/7f8185b4499f4ffaec7abf966fe51331 to your computer and use it in GitHub Desktop.
crypto-better-touch-bar
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/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