Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #Many thanks to Thomas Sileo for this post http://thomassileo.com/blog/2013/09/17/playing-with-python-and-cgminer-rpc-api/
- #Copyright (C) 2014 Martin Vool
- #
- #This program is free software; you can redistribute it and/or
- #modify it under the terms of the GNU General Public License
- #as published by the Free Software Foundation; version 2
- #
- #This program is distributed in the hope that it will be useful,
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- #GNU General Public License for more details.
- #
- #You should have received a copy of the GNU General Public License
- #along with this program; if not, write to the Free Software
- #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- #
- #Copy of the GPLv2 is located at http://www.gnu.org/licenses/gpl-2.0.html
- #Version 1.0
- #For usage see http://wiki.loovsys.eu/index.php/Cgminer_API_python_client_for_bash_and_shell_script_for_profiling_when_system_is_idle
- import socket
- import json
- import fileinput
- def commander(cmd,ip):
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((ip, 4028))
- sock.send(json.dumps(cmd))
- resp = ''
- while 1:
- buf = sock.recv(4096)
- if buf:
- resp += buf
- else:
- break
- values=json.loads(resp[:-1])
- sock.shutdown(socket.SHUT_RDWR)
- sock.close()
- return values
- data=''
- for line in fileinput.input():
- data= '%s%s'%(data,line)
- oneline=' '.join(data.split())
- data=oneline
- alldata=data.split('@',1)
- ip=alldata[-1]
- splt=alldata[0].split(':', 1)
- if len(splt) == 1:
- cmd={'command':splt[0]}
- else:
- cmd={'command':splt[0],'parameter':splt[1]}
- foo=commander(cmd,ip)
- for k,v in foo.iteritems():
- print '---------------'
- print '%s'%k
- try:
- for vv in v:
- print '---------------'
- try:
- for kkk,vvv in vv.iteritems():
- print '%s: %s'%(kkk,vvv)
- except:
- print '%s'%vv
- except:
- print '%s'%v
Advertisement
Add Comment
Please, Sign In to add comment