Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """Tutorial on using the InfluxDB client."""
  3.  
  4. import argparse
  5.  
  6. from influxdb import InfluxDBClient
  7.  
  8. # curl -i -XPOST 'http://localhost:8086/write?db=smog_db' --data-binary 'smog,airQualityIndex=4,sensorId=11 pm10=0.01,pm25=0.02 14340555620000'
  9.  
  10. # curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=smog_db" --data-urlencode "q=SELECT * FROM \"smog\""
  11.  
  12.  
  13. # ssh -i pajtong.pem ec2-user@ec2-52-16-76-3.eu-west-1.compute.amazonaws.com
  14. # scp -i pajtong.pem ec2-user@ec2-52-16-76-3.eu-west-1.compute.amazonaws.com
  15.  
  16. # http://ec2-52-16-76-3.eu-west-1.compute.amazonaws.com:3000
  17. # admin
  18. # admin
  19.  
  20.  
  21. # curl -i -XPOST 'http://localhost:8086/write?db=smog_db' --data-binary 'smog,airQualityIndex=4,sensorId=11 pm10=0.01,pm25=0.02 14340555620000'
  22.  
  23. import requests
  24.  
  25. # http://ec2-52-16-76-3.eu-west-1.compute.amazonaws.com:8086/query?db=smog_db&q=SELECT%20*%20FROM%20pm25
  26. def get_from_url(host='ec2-52-16-76-3.eu-west-1.compute.amazonaws.com', port=8086, query='pm25', sensorId='1'):
  27. """Instantiate a connection to the InfluxDB."""
  28. user = ''
  29. password = ''
  30. dbname = 'smog_db'
  31. query = 'SELECT * FROM ' + query + ' WHERE sensorId=' + '\''+str(sensorId)+ '\''
  32. json_body = []
  33.  
  34. client = InfluxDBClient(host, port, user, password, dbname)
  35.  
  36. print("Querying data: " + query)
  37. result = client.query(query)
  38.  
  39. print("Result: {0}".format(result))
  40.  
  41. # print("Switch user: " + user)
  42. # client.switch_user(user, password)
  43.  
  44. # print("Drop database: " + dbname)
  45. # client.drop_database(dbname)
  46.  
  47. if __name__ == '__main__':
  48. get_from_url(query='pm10', sensorId=17)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement