123456789101112131415161718192021222324252627282930313233343536373839 |
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- 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 previous is not None:
- info['previous'] = previous
- url = self.base_url + metric
- resp = requests.post(url, data=json.dumps(info)).read()
- self.logger.debug('Sent metric "{0}" = "{1}"'.format(metric, current))
- return resp
- def push(self, data):
- self.logger.warn('push() not implemented yet')
- if __name__ == "__main__":
- client = DashingClient(
- 'http://dashing.krombel.de:3030/widgets/',
- 'bitnhmlj47hamrftxkiug')
- client.send('testNumber', 42)
|