Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2017 21:57
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Retrieve Bitcoin address balance from Blockchain API
import sys
import getopt
import urllib2
from optparse import OptionParser
def main():
# variables
btcaddr = ""
baseurl = ""
# build parser
usage = "usage: %prog address"
parser = OptionParser(usage);
# parse argument
(options, args) = parser.parse_args()
if len(args) != 1:
parser.error("incorrect number of arguments")
btcaddr = sys.argv[1]
# get balance
url = baseurl + btcaddr
response = urllib2.urlopen(url)
html =
# if non-zero, write to a results file!
if (html != "0"):
print("Found a non-zero balance at: " + url)
print("Balance has " + html + " Satoshis")
with open("output.log", "a") as outputfile:
outputfile.write(btcaddr + "\t" + html)
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment