12345678910111213141516171819202122232425262728293031323334353637 |
- #!/usr/bin/python
- import json
- import logging
- import requests
- class DashingClient:
- base_url = None
- def __init__(self, base_url, auth_token):
- self.base_url = base_url
- self.auth_token = auth_token
- self.logger = logging.getLogger('dashing')
- def __str__(self):
- return 'Dashing at \'{0}\''.format(self.base_url)
- def send(self, metric, current, previous=None):
- info = {
- 'auth_token': self.auth_token,
- 'current': int(current),
- }
- if not previous is None:
- info['previous'] = previous
- url = self.base_url + metric
- r = requests.post(url, data=json.dumps(info))
- self.logger.debug('Sent metric "{0}" = "{1}"'.format(metric, current))
- return r
- def push(self, data):
- self.logger.warn('push() not implemented yet')
- if __name__ == "__main__":
- d = DashingClient('http://dashing.krombel.de:3030/widgets/', 'bitnhmlj47hamrftxkiug')
- d.send('testNumber', 42)
|