analytics.py 576 B

123456789101112131415161718
  1. import requests
  2. def post_data(field, keys, value):
  3. db = 'news'
  4. influx_host = 'http://localhost:8086/write?db=%s' % db
  5. headers = {'Content-Type': 'application/octet-stream'}
  6. tmpkeys = ",".join(["%s=%s" % (k, v) for k, v in keys.items()])
  7. data = "%s,%s %s" % (field, tmpkeys, value)
  8. print(data)
  9. try:
  10. ret = requests.post(influx_host, data=data, headers=headers)
  11. if ret.status_code // 100 != 2:
  12. print(ret.status_code)
  13. print(ret.text)
  14. print(data, "failed!!")
  15. except Exception as e:
  16. pass