#!/usr/bin/python import sys import os import urllib import xmlrpclib import json api_user=os.getenv('BITMESSAGE_API_USER', 'bitmessage_api_user') ; api_password=os.getenv('BITMESSAGE_API_PASSWORD', 'bitmessage_api_password') ; api_port=os.getenv('BITMESSAGE_API_PORT', '8442') ; # Credentials go into a URL, so they must be percent-encoded: '@' splits the # userinfo, '#' truncates the rest, '/' and ':' change what is parsed as host # and port. Without this a strong password fails here while being perfectly # valid in keys.dat. (A '%' in the password is a separate matter -- it breaks # PyBitmessage's own config reader and makes every API call return 500.) api_link="http://{}:{}@127.0.0.1:{}/".format( urllib.quote(api_user, safe=''), urllib.quote(api_password, safe=''), api_port) api = xmlrpclib.ServerProxy(api_link) network_connections=json.loads(api.clientStatus())['networkConnections'] print "networkConnections:", network_connections if network_connections > 0: sys.exit(0) else: sys.exit(1)