dashing.py 885 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/python
  2. import json
  3. import logging
  4. import requests
  5. class DashingClient:
  6. base_url = None
  7. def __init__(self, base_url, auth_token):
  8. self.base_url = base_url
  9. self.auth_token = auth_token
  10. self.logger = logging.getLogger('dashing')
  11. def __str__(self):
  12. return 'Dashing at \'{0}\''.format(self.base_url)
  13. def send(self, metric, current, previous=None):
  14. info = {
  15. 'auth_token': self.auth_token,
  16. 'current': int(current),
  17. }
  18. if not previous is None:
  19. info['previous'] = previous
  20. url = self.base_url + metric
  21. r = requests.post(url, data=json.dumps(info))
  22. self.logger.debug('Sent metric "{0}" = "{1}"'.format(metric, current))
  23. return r
  24. def push(self, data):
  25. self.logger.warn('push() not implemented yet')
  26. if __name__ == "__main__":
  27. d = DashingClient('http://dashing.krombel.de:3030/widgets/', 'bitnhmlj47hamrftxkiug')
  28. d.send('testNumber', 42)