Skip to content

Instantly share code, notes, and snippets.

@fuzzy
Created February 13, 2015 08:36
Show Gist options
  • Save fuzzy/d5a682972465027a11fd to your computer and use it in GitHub Desktop.
Save fuzzy/d5a682972465027a11fd to your computer and use it in GitHub Desktop.
MPOS api in python, no error handling, but full api coverage, it is hereby placed in the public domain
import json
import types
import urllib
import urllib2
class Mpos:
def __init__(self, apiUri=None, apiKey=None, UserId=None):
self.apiUri = apiUri
self.apiKey = apiKey
self.UserId = UserId
self.payload = {
'id': self.UserId
'page': 'api',
'action': None,
'api_key': self.apiKey
}
self.headers = {
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0'
}
def __make_call(self, action=None, args=None):
if not action:
return False
else:
# prep the payload
payload = self.payload
payload['action'] = action
# if we have args, lets add them
if type(args) in (types.ListType, types.TupleType):
for pair in args:
payload[pair[0]] = pair[1]
elif type(args) == types.DictType:
for key in args.keys():
payload[key] = args[key]
# build the actual request finally
request = urllib2.Request(self.apiUri, urllib.urlencode(payload), self.headers)
# and hand off the result
return json.loads(urllib2.urlopen(request).read())
def GetBlockCount(self):
return self.__make_call('getblockcount')
def GetBlocksFound(self):
return self.__make_call('getblocksfound')
def GetBlockStats(self):
return self.__make_call('getblockstats')
def GetCurrentWorkers(self):
return self.__make_call('getcurrentworkers')
def GetDashboardData(self):
return self.__make_call('getdashboarddata')
def GetDifficulty(self):
return self.__make_call('getdifficulty')
def GetEstimatedTime(self):
return self.__make_call('getestimatedtime')
def GetHourlyHashrates(self):
pass # Currently broken according to MPOS api docs
def GetNavBarData(self):
return self.__make_call('getnavbardata')
def GetPoolHashrate(self):
return self.__make_call('getpoolhashrate')
def GetPoolInfo(self):
return self.__make_call('getpoolinfo')
def GetPoolSharerate(self):
return self.__make_call('getpoolsharerate')
def GetPoolStatus(self):
return self.__make_call('getpoolstatus')
def GetTimeSinceLastBlock(self):
return self.__make_call('gettimesincelastblock')
def GetTopContributors(self):
return self.__make_call('gettopcontributors')
def GetUserBalance(self):
return self.__make_call('getuserbalance')
def GetUserHashrate(self):
return self.__make_call('getuserhashrate')
def GetUserSharerate(self):
return self.__make_call('getusersharerate')
def GetUserStatus(self):
return self.__make_call('getuserstatus')
def GetUserTransactions(self):
return self.__make_call('getusertransactions')
def GetUserWorkers(self):
return self.__make_call('getuserworkers')
def Public(self):
return self.__make_call('public')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment