In [20]:
#get miners
import requests, pprint

url = "http://127.0.0.1:5005/"

r = requests.get(url + "miner/")
print pprint.pprint(r.json()['_items'])


[{u'_id': u'52eec81c823ac22d646cc73f',
  u'_links': {u'self': {u'href': u'/miner/Thorin', u'title': u'miner'}},
  u'created': u'Sun, 02 Feb 2014 22:35:08 GMT',
  u'etag': u'c311bc2be3073181ff04f9c147b5f57a84560c49',
  u'hostname': u'thorin.local',
  u'name': u'Thorin',
  u'updated': u'Sun, 02 Feb 2014 22:35:08 GMT'},
 {u'_id': u'52eec832823ac22d646cc740',
  u'_links': {u'self': {u'href': u'/miner/Radagast', u'title': u'miner'}},
  u'created': u'Sun, 02 Feb 2014 22:35:30 GMT',
  u'etag': u'07b2801af912c93b18decf0a2510e4305e60cb0a',
  u'hostname': u'radagast.local',
  u'name': u'Radagast',
  u'updated': u'Sun, 02 Feb 2014 22:35:30 GMT'},
 {u'_id': u'52eec84a823ac22d646cc741',
  u'_links': {u'self': {u'href': u'/miner/Pippin', u'title': u'miner'}},
  u'created': u'Sun, 02 Feb 2014 22:35:54 GMT',
  u'etag': u'ae50584b3a38adcaf16334992b3423ff4a2ee385',
  u'hostname': u'pippin.local',
  u'name': u'Pippin',
  u'updated': u'Sun, 02 Feb 2014 22:35:54 GMT'},
 {u'_id': u'52eec869823ac22d646cc742',
  u'_links': {u'self': {u'href': u'/miner/Alatar', u'title': u'miner'}},
  u'created': u'Sun, 02 Feb 2014 22:36:25 GMT',
  u'etag': u'e727a4dcd7f16e6933b00b21d0466afdde713981',
  u'hostname': u'alatar.local',
  u'name': u'Alatar',
  u'updated': u'Sun, 02 Feb 2014 22:36:25 GMT'},
 {u'_id': u'52eec87f823ac22d646cc743',
  u'_links': {u'self': {u'href': u'/miner/Pallando', u'title': u'miner'}},
  u'created': u'Sun, 02 Feb 2014 22:36:47 GMT',
  u'etag': u'd24f0fec5f46e24dc7c7cf65c4312e27a6e14652',
  u'hostname': u'pallando.local',
  u'name': u'Pallando',
  u'updated': u'Sun, 02 Feb 2014 22:36:47 GMT'},
 {u'_id': u'52eec88e823ac22d646cc744',
  u'_links': {u'self': {u'href': u'/miner/Gandalf', u'title': u'miner'}},
  u'created': u'Sun, 02 Feb 2014 22:37:02 GMT',
  u'etag': u'2d66e22d28ad20d36eb8ea56df423f4f3e50cd9b',
  u'hostname': u'gandalf.local',
  u'name': u'Gandalf',
  u'updated': u'Sun, 02 Feb 2014 22:37:02 GMT'},
 {u'_id': u'52eec8a9823ac22d646cc745',
  u'_links': {u'self': {u'href': u'/miner/Gimli', u'title': u'miner'}},
  u'created': u'Sun, 02 Feb 2014 22:37:29 GMT',
  u'etag': u'a314d5b2afdb156825094dc22e5d51caaa7e8489',
  u'hostname': u'gimli.local',
  u'name': u'Gimli',
  u'updated': u'Sun, 02 Feb 2014 22:37:29 GMT'}]
None

In [17]:
#post a miner
import requests, json

url = "http://127.0.0.1:5005/miner/"

payload = {  'name': 'Gimli', 'hostname': 'gimli.local' }
headers = {"content-type": "application/json"}

r = requests.post(url, headers = headers, data = json.dumps(payload))
print r.text


{"status": "OK", "updated": "Sun, 02 Feb 2014 22:37:29 GMT", "etag": "a314d5b2afdb156825094dc22e5d51caaa7e8489", "_links": {"self": {"href": "/miner/52eec8a9823ac22d646cc745", "title": "miner"}}, "name": "52eec8a9823ac22d646cc745"}

In [33]:
#get stats
import requests

url = "http://127.0.0.1:5005/"

r = requests.get(url + "stat/")
print r.text


{"_items": [{"updated": "Sun, 02 Feb 2014 23:35:25 GMT", "created": "Sun, 02 Feb 2014 23:35:25 GMT", "when": "Sun, 02 Feb 2014 16:35:25 GMT", "miner": "52eec81c823ac22d646cc73f", "etag": "fce89651de6ff2d2be058603c4feda6e6802ce84", "_links": {"self": {"href": "/stat/52eed63d823ac22f33379ae2", "title": "Stat"}}, "_id": "52eed63d823ac22f33379ae2", "hashrate": 5}], "_links": {"self": {"href": "/stat", "title": "stat"}, "parent": {"href": "", "title": "home"}}}

In [32]:
#post a stat
import requests, json, datetime

url = "http://127.0.0.1:5005/stat/"
now = datetime.datetime.now()
payload = { 
  'hashrate': 5, 
  'miner': '52eec81c823ac22d646cc73f', 
  'when': now.strftime('%a, %d %b %Y %X GMT'),
}
headers = {"content-type": "application/json"}

r = requests.post(url, headers = headers, data = json.dumps(payload))
print r.text


{"status": "OK", "updated": "Sun, 02 Feb 2014 23:35:25 GMT", "_id": "52eed63d823ac22f33379ae2", "_links": {"self": {"href": "/stat/52eed63d823ac22f33379ae2", "title": "Stat"}}, "etag": "fce89651de6ff2d2be058603c4feda6e6802ce84"}

In [ ]: