#!/usr/bin/env ruby
# encoding: UTF-8
require 'uri'
require 'open-uri'
require 'nokogiri'
class Btc_Balance
def convert_btc_unit(balance)
final = balance/100000000.0
return final
end
def get_balance(addr)
url = "https://blockchain.info/q/addressbalance/" << addr
data = URI.parse(url).read
doc = Nokogiri::HTML(data)
balance = doc.search('//html/body/p').text
return balance
end
end
def main
btc_account = Btc_Balance.new
addr = "your BTC address"
balance = btc_account.get_balance(addr)
final_balance = btc_account.convert_btc_unit(balance.to_i)
puts "%.8f" % final_balance << " BTC"
end
main