Advertisement
Guest User

Untitled

a guest
May 1st, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import forecastio
  2. from influxdb import InfluxDBClient
  3.  
  4. client = InfluxDBClient(host='YOUR_IP',
  5. port=8086,
  6. database='YOURDB',
  7. username='username',
  8. password='password',
  9. verify_ssl=False)
  10.  
  11. api_key = "forecast.io api-key"
  12. lat = -80.253391
  13. lng = -59.897461
  14.  
  15. forecast = forecastio.load_forecast(api_key, lat, lng)
  16. current = forecast.currently()
  17. temp = float(current.temperature)
  18. humidity = float(current.humidity * 100)
  19.  
  20. points = []
  21. point = {
  22. "measurement": 'temp',
  23. "tags": {
  24. "sensor": "Outside-forecastio"
  25. },
  26. "fields": {
  27. "value": temp
  28. }
  29. }
  30. points.append(point)
  31. point = {
  32. "measurement": 'humidity',
  33. "tags": {
  34. "sensor": "Outside-forecastio"
  35. },
  36. "fields": {
  37. "value": humidity
  38. }
  39. }
  40. points.append(point)
  41. client.write_points(points)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement