Bitcoin Forum

Bitcoin => Project Development => Topic started by: super3 on June 08, 2013, 07:18:27 AM



Title: Rought Python Network Sync Check
Post by: super3 on June 08, 2013, 07:18:27 AM
Its some real terrible code, but figured someone might be able to use it. Useful to check how much of the total blocks are synced with your local bitcoind.

Code:
import commands
import urllib2

# get synced blocks
info = commands.getstatusoutput('bitcoind getinfo')
info = info[1][1:-1]
info = info.split(',')[4].strip()
blocks = float(info.split(':')[1].strip())

# get total blocks
url = 'https://blockexplorer.com/q/getblockcount'
data = urllib2.urlopen(url).read(200)
data = data.split("\n")
for line in data:
        totblocks = float(line)

# calculate
print(str((blocks/totblocks)*100)+"%")