Last active
December 22, 2015 06:19
-
-
Save dmerrick/6430655 to your computer and use it in GitHub Desktop.
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
| bitcoin_earnings |
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
| 2.0 |
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 'open-uri' | |
| require 'json' # ruby 1.9+ | |
| if $DEBUG | |
| # development gems | |
| require 'rubygems' | |
| require 'awesome_print' | |
| require 'pry' | |
| end | |
| # take a command line argument if provided | |
| address = ARGV.first || "1JT86GVai2r7sixvsJfJxNWHon9Dep2erh" | |
| # cost of the mining rig | |
| cost_of_miner = 0.4416 # BTC | |
| # save the current time | |
| time = DateTime.now.strftime(" %H:%M %-m/%-d/%Y ") | |
| time = "-" * 10 + time + "-" * 10 | |
| # find current BTC->USD exchange rate (weighted average) | |
| current_value_url = 'http://api.bitcoinaverage.com/no-mtgox/ticker/USD' | |
| usd_json = JSON.parse(URI.parse(current_value_url).read) | |
| current_value = usd_json["last"].to_f | |
| # find total BTC mined | |
| bitcoin_stats_url = "http://eligius.st/~luke-jr/raw/7/balances.json" | |
| btc_json = JSON.parse(URI.parse(bitcoin_stats_url).read) | |
| total_mined = btc_json[address]["balance"].to_i * 0.00000001 | |
| total_mined = total_mined.round(10) | |
| # ROI stats | |
| break_even = cost_of_miner - total_mined | |
| break_even_progress = ((total_mined / cost_of_miner) * 100.0).round(2) | |
| # approximate USD earned, rounded to 2 decimal places | |
| total_earned = (current_value * total_mined).round(2).to_s | |
| total_earned += "0" if total_earned.to_s.split('.').last.size != 2 | |
| puts time | |
| puts "Approximate BTC mined: #{total_mined}" | |
| puts "USD rate (current avg.): $#{current_value}" | |
| puts "-" * time.size | |
| puts "Progress to positive ROI: #{break_even_progress}%" | |
| puts "BTC left to positive ROI: #{break_even}" | |
| puts "-" * time.size | |
| puts "Approximate USD earned: $#{total_earned}" | |
| puts "-" * time.size |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: