Add --balance option
This commit is contained in:
parent
70d506ff00
commit
e145147a00
2
README
2
README
@ -11,4 +11,6 @@ Options:
|
|||||||
--testnet use testnet subdirectory and address type
|
--testnet use testnet subdirectory and address type
|
||||||
--reserve import as a reserve key, i.e. it won't show in the
|
--reserve import as a reserve key, i.e. it won't show in the
|
||||||
adress book
|
adress book
|
||||||
|
--balance=KEY_BALANCE
|
||||||
|
prints balance of KEY_BALANCE
|
||||||
|
|
||||||
|
|||||||
18
pywallet.py
18
pywallet.py
@ -17,6 +17,7 @@ import string
|
|||||||
import exceptions
|
import exceptions
|
||||||
import hashlib
|
import hashlib
|
||||||
import random
|
import random
|
||||||
|
import urllib
|
||||||
|
|
||||||
max_version = 32500
|
max_version = 32500
|
||||||
addrtype = 0
|
addrtype = 0
|
||||||
@ -792,6 +793,16 @@ def importprivkey(db, sec, label, reserve):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def balance(site, address):
|
||||||
|
page=urllib.urlopen("%s=%s" % (site, address))
|
||||||
|
json_acc = json.loads(page.read().split("<end>")[0])
|
||||||
|
if json_acc['0'] == 0:
|
||||||
|
return "Invalid address"
|
||||||
|
elif json_acc['0'] == 2:
|
||||||
|
return "Never used"
|
||||||
|
else:
|
||||||
|
return json_acc['balance']
|
||||||
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -823,8 +834,15 @@ def main():
|
|||||||
parser.add_option("--reserve", dest="reserve", action="store_true",
|
parser.add_option("--reserve", dest="reserve", action="store_true",
|
||||||
help="import as a reserve key, i.e. it won't show in the adress book")
|
help="import as a reserve key, i.e. it won't show in the adress book")
|
||||||
|
|
||||||
|
parser.add_option("--balance", dest="key_balance",
|
||||||
|
help="prints balance of KEY_BALANCE")
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
if options.key_balance is not None:
|
||||||
|
print(balance('http://bitcoin.site50.net/balance.php?adresse', options.key_balance))
|
||||||
|
exit(0)
|
||||||
|
|
||||||
if options.dump is None and options.key is None:
|
if options.dump is None and options.key is None:
|
||||||
print "A mandatory option is missing\n"
|
print "A mandatory option is missing\n"
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user