Advertisement
KevinOrr

Untitled

Aug 30th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import socket
  4. import json
  5. import time
  6.  
  7. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  8. sock.connect(('127.0.0.1', 4028))
  9.  
  10. sock.send(bytes(json.dumps({'command': 'summary'}), 'UTF-8'))
  11.  
  12. resp = ''
  13. no_resp = 0
  14. while 1:
  15.     buf = sock.recv(4096)
  16.     if buf:
  17.         resp += buf
  18.         no_resp = 0
  19.     elif resp and not buf:
  20.         no_resp += 1
  21.     if no_resp >= 10:
  22.         break
  23.  
  24. result = json.loads(resp[:-1])
  25. print(result)
  26.  
  27. sock.shutdown(socket.SHUT_RDWR)
  28. sock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement