Skip to content

Instantly share code, notes, and snippets.

@Demontager
Created May 16, 2014 19:07
Show Gist options
  • Save Demontager/8714a85b5a4aeedf1f3b to your computer and use it in GitHub Desktop.
Save Demontager/8714a85b5a4aeedf1f3b to your computer and use it in GitHub Desktop.
import socket
import json
import sys
def linesplit(socket):
buffer = socket.recv(4096)
done = False
while not done:
more = socket.recv(4096)
if not more:
done = True
else:
buffer = buffer+more
if buffer:
return buffer
api_command = sys.argv[1].split('|')
if len(sys.argv) < 3:
api_ip = '127.0.0.1'
api_port = 4028
else:
api_ip = sys.argv[2]
api_port = sys.argv[3]
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((api_ip,int(api_port)))
if len(api_command) == 2:
s.send(json.dumps({"command":api_command[0],"parameter":api_command[1]}))
else:
s.send(json.dumps({"command":api_command[0]}))
response = linesplit(s)
response = response.replace('\x00','')
response = json.loads(response)
if api_command[0]=="devs":
j=1
for i in response["DEVS"]:
print j, i["Status"]
j+=1
else:
print response
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment