willphase

cointerra.py

Feb 27th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. #!/usr/bin/env python2.7
  2.  
  3. # Original Copyright 2013 Setkeh Mkfr
  4. #
  5. # This program is free software; you can redistribute it and/or modify it under
  6. # the terms of the GNU General Public License as published by the Free Software
  7. # Foundation; either version 3 of the License, or (at your option) any later
  8. # version.  See COPYING for more details.
  9.  
  10. #Short Python Example for connecting to The Cgminer API
  11. #Written By: setkeh <https://github.com/setkeh>
  12. #Thanks to Jezzz for all his Support.
  13. #NOTE: When adding a param with a pipe | in bash or ZSH you must wrap the arg in quotes
  14. #E.G "pga|0"
  15.  
  16. import socket
  17. import json
  18. import sys
  19. import time
  20. import os
  21.  
  22. def linesplit(socket):
  23.     buffer = socket.recv(4096)
  24.     done = False
  25.     while not done:
  26.         more = socket.recv(4096)
  27.         if not more:
  28.             done = True
  29.         else:
  30.             buffer = buffer+more
  31.     if buffer:
  32.         return buffer
  33.  
  34. api_command = "devs"
  35. api_port = 4028
  36. api_ip = sys.argv[1]
  37.  
  38. s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  39. s.connect((api_ip,int(api_port)))
  40. s.send(json.dumps({"command":api_command}))
  41.  
  42. response = linesplit(s)
  43. response = response.replace('\x00','')
  44. response = json.loads(response)
  45. err = False
  46. dev0 = response['DEVS'][0]['MHS 5s']
  47. dev1 = response['DEVS'][1]['MHS 5s']
  48. print "Device " + api_ip + " 0:" + str(dev0) + " 1:" + str(dev1)
  49. if dev0 < 100000 or dev1 < 100000:
  50.   print "Restarting cgminer"
  51.   os.system("sshpass -p cointerra ssh root@" + api_ip + " /etc/init.d/S99cgminer restart")
  52.   time.sleep(5)
  53. s.close()
Advertisement
Add Comment
Please, Sign In to add comment