Bitcoin Forum
February 21, 2018, 09:52:44 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Rought Python Network Sync Check  (Read 614 times)
super3
Legendary
*
Offline Offline

Activity: 1091
Merit: 1000


View Profile WWW
June 08, 2013, 07:18:27 AM
 #1

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)+"%")

Bitcoin Dev / Storj - Decentralized Cloud Storage. Winner of Texas Bitcoin Conference Hackathon 2014. / Peercoin Web Lead / Primecoin Web Lead / Armory Guide Author / "Am I the only one that trusts Dogecoin more than the Federal Reserve?"
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!