├── MANIFEST.in ├── .gitignore ├── setup.py ├── LICENSE ├── pycgminer.py └── README.rst /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst LICENSE -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | build/ 3 | dist/ 4 | pycgminer.egg-info/ 5 | .sass-cache 6 | .DS_Store 7 | *tar.gz 8 | *.zip 9 | .pypirc 10 | docs/_build 11 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup 3 | 4 | 5 | def read(fname): 6 | return open(os.path.join(os.path.dirname(__file__), fname)).read() 7 | 8 | setup( 9 | name="pycgminer", 10 | version="0.1.1", 11 | author="Thomas Sileo", 12 | author_email="thomas.sileo@gmail.com", 13 | description="Cgminer RPC API wrapper.", 14 | license="MIT", 15 | keywords="cgminer", 16 | url="https://github.com/tsileo/pycgminer", 17 | py_modules=["pycgminer"], 18 | long_description=read("README.rst"), 19 | install_requires=[], 20 | classifiers=[ 21 | "Development Status :: 4 - Beta", 22 | "Intended Audience :: Developers", 23 | "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", 24 | "Programming Language :: Python", 25 | ], 26 | # test_suite="test_globster", 27 | ) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Thomas Sileo 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /pycgminer.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import json 3 | 4 | 5 | class CgminerAPI(object): 6 | """ Cgminer RPC API wrapper. """ 7 | def __init__(self, host='localhost', port=4028): 8 | self.data = {} 9 | self.host = host 10 | self.port = port 11 | 12 | def command(self, command, arg=None): 13 | """ Initialize a socket connection, 14 | send a command (a json encoded dict) and 15 | receive the response (and decode it). 16 | """ 17 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 18 | 19 | try: 20 | sock.connect((self.host, self.port)) 21 | payload = {"command": command} 22 | if arg is not None: 23 | # Parameter must be converted to basestring (no int) 24 | payload.update({'parameter': unicode(arg)}) 25 | 26 | sock.send(json.dumps(payload)) 27 | received = self._receive(sock) 28 | finally: 29 | sock.shutdown(socket.SHUT_RDWR) 30 | sock.close() 31 | 32 | return json.loads(received[:-1]) 33 | 34 | def _receive(self, sock, size=4096): 35 | msg = '' 36 | while 1: 37 | chunk = sock.recv(size) 38 | if chunk: 39 | msg += chunk 40 | else: 41 | break 42 | return msg 43 | 44 | def __getattr__(self, attr): 45 | """ Allow us to make command calling methods. 46 | 47 | >>> cgminer = CgminerAPI() 48 | >>> cgminer.summary() 49 | 50 | """ 51 | def out(arg=None): 52 | return self.command(attr, arg) 53 | return out 54 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | Pycgminer 3 | ========= 4 | 5 | Python wrapper for `cgminer `_ RPC API. 6 | 7 | .. image:: https://img.shields.io/pypi/v/pycgminer.svg 8 | :target: https://crate.io/packages/pycgminer 9 | 10 | .. image:: https://img.shields.io/pypi/dm/pycgminer.svg 11 | :target: https://crate.io/packages/pycgminer 12 | 13 | 14 | Installation 15 | ------------ 16 | 17 | .. code-block:: 18 | 19 | $ pip install pycgminer 20 | 21 | 22 | QuickStart 23 | ---------- 24 | 25 | .. code-block:: python 26 | 27 | from pycgminer import CgminerAPI 28 | 29 | cgminer = CgminerAPI() 30 | 31 | summary = cgminer.summary() 32 | 33 | my_asic = cgminer.asc(0) 34 | 35 | 36 | Donation 37 | -------- 38 | 39 | If you like my work, please consider donating: 40 | 41 | BTC 18ZcxHsKnc4a1AhnThQ2tiLVjQehxKaGFX 42 | 43 | 44 | License (MIT) 45 | ------------- 46 | 47 | Copyright (c) 2013 Thomas Sileo 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 50 | 51 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 52 | 53 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 54 | --------------------------------------------------------------------------------