import sys
def get_ccminer_api_stats(miner, api_port, command):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (miner, int(api_port))
print ("Connecting to API@" + miner + ":" + str(api_port))
try:
sock.connect((server_address))
print ("Connected to API")
sock.sendall(command)
data = sock.recv(4096)
data = data.replace('|\x00','')
data_split = data.split(';')
keys = []
values = []
for item in data_split:
item_split = item.split('=')
keys.append(item_split[0])
values.append(item_split[1])
api_json = {}
i = 0
while i < len(keys):
api_json[keys[i]] = values[i]
i+=1
except Exception as err:
api_json = {}
if command == 'summary':
api_json['KHS'] = 'crashed'
return api_json
#api_commands = ['help', 'summary', 'threads', 'pool', 'histo', 'hwinfo', 'meminfo']
miner = sys.argv[1]
api_port = sys.argv[2]
command = sys.argv[3]
stats = get_ccminer_api_stats(miner, api_port, command)
print (stats)