Advertisement
Guest User

Untitled

a guest
Jul 18th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. import json
  2. import requests
  3. from time import ctime
  4.  
  5. req = requests.get('https://www.wemineltc.com/api?api_key=c29e4832d0d047dbb65bc817e5316341200f51491de9ea8188e0eb49dd6b94a5', verify=False)
  6.  
  7. #req = requests.get('http://192.168.10.109/api.html')
  8. reqDict = json.loads(req.content)
  9.  
  10. displayedNamesList = ('Username', 'Round shares', 'Total hashrate', 'Balance', 'Round estimate', 'Payout history')
  11. i = 0
  12. replacedReqDict = {}
  13. for dictKey in reqDict.keys():
  14.     if type(reqDict[dictKey]) == unicode:
  15.         replacedReqDict[displayedNamesList[i]] = reqDict[dictKey]
  16.         i += 1
  17.     elif type(reqDict[dictKey]) == dict:
  18.         replacedReqDict[dictKey] = reqDict[dictKey]
  19.  
  20. def formatText(key, value, offset=20):
  21.     key = str(key)
  22.     value = str(value)
  23.     if key in ('Balance', 'Round estimate', 'Payout history'):
  24.         value = value[0:6] + ' LTC'
  25.     elif key == "Alive":
  26.         value = str(bool(value))
  27.     elif key == "Last share":
  28.         value = ctime(float(value))
  29.     if key == "Worker":
  30.         outputString = '\n' + key + ':' + value.rjust(offset - len(str(key)) + len(str(value)))
  31.     else:
  32.         outputString = key + ':' + value.rjust(offset - len(str(key)) + len(str(value)))
  33.     return outputString
  34.  
  35. for dictKey in sorted(replacedReqDict):
  36.     if dictKey == 'workers':
  37.         workersDict = replacedReqDict.get('workers')
  38.         for workersDictKey in sorted(workersDict):
  39.             workerStatDict = workersDict.get(workersDictKey)
  40.             print formatText("Worker", workersDictKey, 24)
  41.  
  42.             displayedNamesWorkerStatList = ('Alive', 'Hashrate', 'Last share')
  43.             i = 0
  44.             replacedWorkerStatDict = {}
  45.             for workerStatDictKey in sorted(workerStatDict.keys()):
  46.                  replacedWorkerStatDict[displayedNamesWorkerStatList[i]] = workerStatDict[workerStatDictKey]
  47.                  i += 1
  48.  
  49.             for replacedWorkerStatDictKey in sorted(replacedWorkerStatDict):
  50.                print formatText(replacedWorkerStatDictKey, replacedWorkerStatDict.get(replacedWorkerStatDictKey),24)
  51.     else:
  52.         print formatText(dictKey, replacedReqDict.get(dictKey), 24)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement