Skip to content

Instantly share code, notes, and snippets.

@jdrews
Created May 1, 2016 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdrews/37f374a6e196cfdc81aa27196534c4cf to your computer and use it in GitHub Desktop.
Save jdrews/37f374a6e196cfdc81aa27196534c4cf to your computer and use it in GitHub Desktop.
Grab temp and humidity from forecast.io and store in influxdb. Poll trigger via cron
import forecastio
from influxdb import InfluxDBClient
client = InfluxDBClient(host='YOUR_IP',
port=8086,
database='YOURDB',
username='username',
password='password',
verify_ssl=False)
api_key = "forecast.io api-key"
lat = -80.253391
lng = -59.897461
forecast = forecastio.load_forecast(api_key, lat, lng)
current = forecast.currently()
temp = float(current.temperature)
humidity = float(current.humidity * 100)
points = []
point = {
"measurement": 'temp',
"tags": {
"sensor": "Outside-forecastio"
},
"fields": {
"value": temp
}
}
points.append(point)
point = {
"measurement": 'humidity',
"tags": {
"sensor": "Outside-forecastio"
},
"fields": {
"value": humidity
}
}
points.append(point)
client.write_points(points)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment