Skip to content

Instantly share code, notes, and snippets.

@topher6345
Last active October 27, 2015 08:55
Show Gist options
  • Save topher6345/30619b3beb37d327e9c4 to your computer and use it in GitHub Desktop.
Save topher6345/30619b3beb37d327e9c4 to your computer and use it in GitHub Desktop.
Print out the change in the last hour of various crypotcurrencies
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'net/http'
require 'colorize'
def fetch(url)
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
JSON.parse(data)
end
coinmarketcap = fetch "http://coinmarketcap.northpole.ro/api/all.json"
coinmarketcap["markets"].reverse.each do |c|
price = c["change1h"].green if c["change1h"].to_f > 0
price = c["change1h"].red if c["change1h"].to_f < 0
puts %Q[ #{c["name"]} #{price}]
end
require 'rubygems'
require 'json'
require 'net/http'
require 'colorize'
def fetch(url)
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
JSON.parse(data)
end
coinmarketcap = fetch "http://coinmarketcap.northpole.ro/api/all.json"
coinmarketcap["markets"].reverse.each do |c|
price = c["change1h"].green if c["change1h"].to_f > 0
price = c["change1h"].red if c["change1h"].to_f < 0
puts %Q[ #{c["name"]} #{price}]
end
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'net/http'
require 'colorize'
def fetch(url)
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
JSON.parse(data)
end
coinmarketcap = fetch "http://coinmarketcap.northpole.ro/api/all.json"
coinmarketcap["markets"].sort_by! {|coin| coin["change1h"].to_f }
coinmarketcap["markets"].each do |c|
next if c["change1h"].to_f.zero?
price = "+#{c['change1h']}".green if c["change1h"].to_f > 0
price = c["change1h"].red if c["change1h"].to_f < 0
puts %Q[ #{c["name"]} #{price}]
end
@topher6345
Copy link
Author

to install

sudo mv coinmarket usr/bin/coinmarket
sudo chmod 777 usr/bin/coinmarket
sudo chmod u+x usr/bin/coinmarket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment