Skip to content

Instantly share code, notes, and snippets.

@lukem512
Created May 12, 2017 21:57
Show Gist options
  • Save lukem512/4cd0ac166b343f726bd40cedfad7c01e to your computer and use it in GitHub Desktop.
Save lukem512/4cd0ac166b343f726bd40cedfad7c01e to your computer and use it in GitHub Desktop.
Retrieve Bitcoin address balance from Blockchain API
#!/usr/bin/python
import sys
import getopt
import urllib2
from optparse import OptionParser
def main():
# variables
btcaddr = ""
baseurl = "https://blockchain.info/q/addressbalance/"
# 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")
else:
btcaddr = sys.argv[1]
# get balance
url = baseurl + btcaddr
response = urllib2.urlopen(url)
html = response.read()
# 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__":
main()
@VardanMnatsakanyan
Copy link

Hello everyone and thank you for paying me your attention. For example, some blockchain consumers still don't know what they actually used, what blockchain is, and that a miracle actually saved them from bankruptcy. For example, that the safest program in the world is available. And the fastest transfers in the world with blockchain. The most decentralized key and lock program or most secure program in the blockchain world. The easiest money transfer program in the world is blockchain. The most independent banking resources and daily updated information from exchanges around the world, first blockchain. And much more. Some dealers or marketing managers have sent my translations and are making a fool of themselves. And many are probably lucky. You need to go to the psychiatric hospital for treatment or give up marketing, do something else in business, or ask them for a certificate again. You should probably go to school, for example web studies, study marketing again. Look what kind of referral a letter was sent to me from the marketing mining site. I don't know how his understands that?????

Then there are limits to literacy, ladies and gentlemen. Look at this.

tag:blogger.com,1999:blog-90757997343631876752024-01-24T01:59:19.935-08:00<title type='text'>$I7O_OOO</title>Unknownnoreply@blogger.comBlogger0125

@VardanMnatsakanyan
Copy link

tag:blogger.com,1999:blog-90757997343631876752024-01-24T01:59:19.935-08:00<title type='text'>$I7O_OOO</title>Unknownnoreply@blogger.comBlogger0125

@biroistvangmailcom
Copy link

i just changed your code a bit for python3:
` #!/usr/bin/python

import sys
import getopt
import urllib.request
from optparse import OptionParser

def main():

variables

btcaddr = ""
baseurl = "https://blockchain.info/q/addressbalance/"

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")
else:
btcaddr = sys.argv[1]

get balance

url = baseurl + btcaddr
response = urllib.request.urlopen(url)
html = int(response.read())
btcbal = (html / 100000000)

if non-zero, write to a results file!

if (html != "0"):
print("Found a non-zero balance at: " + url)
print(str(btcbal) + "BTC")
with open("output.log", "a") as outputfile:
outputfile.write(btcaddr + "-balance-:" + str(btcbal) + "\n")

if name == "main":
main()
`

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