From 447a437f18506433a1d94d2ebb2a2847c60e123a Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Tue, 22 Mar 2016 21:51:18 +0300 Subject: [PATCH] Exception handling, implement norpc option --- contrib/seeds/getseeds.py | 35 +++++++++++++++++++++++++---------- 1 files changed, 25 insertions(+), 10 deletions(-) diff --git a/contrib/seeds/getseeds.py b/contrib/seeds/getseeds.py index a739e7a..2d61795 100755 --- a/contrib/seeds/getseeds.py +++ b/contrib/seeds/getseeds.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + ### ### Automatic seeding over HTTP ### (C) 2016 Alex D. @@ -5,19 +7,28 @@ ### http://www.gnu.org/licenses/agpl-3.0.en.html ### +import os +import sys import json import random import urllib2 - -import os import platform + +sources = ['http://dalexhz1.cloudapp.net', 'http://dalexhz2.cloudapp.net', 'http://dalexhz4.cloudapp.net', 'http://dalexhz5.cloudapp.net'] +data = urllib2.urlopen(random.choice(sources)) + +if 'norpc' in sys.argv: + for node in json.load(data): + print node + sys.exit() + ### This module is required to function properly: ### https://github.com/jgarzik/python-bitcoinrpc +import errno from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException - -sources = ['http://dalexhz1.cloudapp.net', 'http://dalexhz2.cloudapp.net', 'http://dalexhz4.cloudapp.net', 'http://dalexhz5.cloudapp.net'] +from socket import error as socket_error def confFile(): folder = '' @@ -74,13 +85,17 @@ if 'rpclisten' in contents.keys(): url = "http://"+rpcuser+":"+rpcpassword+"@"+rpclisten+":"+rpcport+"/" access = AuthServiceProxy(url) -data = json.load(urllib2.urlopen(random.choice(sources))) -for node in data: +for node in json.load(data): print 'Adding', node try: access.addnode(node, 'add') - except: - print 'Already added' - pass - \ No newline at end of file + except socket_error, e: + if e.errno == errno.ECONNREFUSED: + print 'Unable to communicate with Novacoin RPC' + break + except JSONRPCException, e: + if e.code == -23: + print 'Already added' + continue + break -- 1.7.1