Skip to content

Instantly share code, notes, and snippets.

@elsehow
Last active July 4, 2017 00:47
Show Gist options
  • Save elsehow/67103c882cb9f4717c41a69e542b675e to your computer and use it in GitHub Desktop.
Save elsehow/67103c882cb9f4717c41a69e542b675e to your computer and use it in GitHub Desktop.
python API for MPOS (mining portal open source)
from functools import partial
import requests
class MPOS (object):
'''
API for MPOS (Mining Portal Open Source).
https://github.com/MPOS/php-mpos/wiki/API-Reference
'''
def __init__ (self, url, api_key, id=None):
self.url = url
self.api_key = api_key
self.id = id
def set_method (name, fn):
setattr(self.__class__, name, staticmethod(fn))
for method in [
'public',
'getblockcount',
'getdifficulty',
'getpoolhashrate',
'getblocksfound',
'getcurrentworkers',
'getdashboarddata',
'getdifficulty',
'getestimatedtime',
'gethourlyhashrates',
'getnavbardata',
'getpoolhashrate',
'getpoolinfo',
'getpoolsharerate',
'getpoolstatus',
'gettimesincelastblock',
'gettopcontributors',
# private methods,
# need to pass params={ 'id': your-id }
'getuserbalance',
'getuserhashrate',
'getusersharerate',
'getuserstatus',
'getusertransactions',
'getuserworkers',
]:
# blame it on the lisp
# got you feeling crisp
set_method(method,
# go partial
partial(
# its your birthday
self.__class__._request,
# apply args
# like its your birthday
self, method ))
def _request_route (self, method, params=None):
route = '{!s}index.php?page=api&action={!s}&api_key={!s}'\
.format(self.url, method, self.api_key)
if params:
for param, val in params.items():
route+='&{!s}={!s}'.format(param, val)
return route
def _request (self, method, **kwargs):
return requests.get(
self._request_route(method)
).json()[method]['data']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment