Skip to content

Instantly share code, notes, and snippets.

@ericpulvino
Last active September 26, 2016 00:37
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 ericpulvino/b7753c1f598642f3bbd64895553232db to your computer and use it in GitHub Desktop.
Save ericpulvino/b7753c1f598642f3bbd64895553232db to your computer and use it in GitHub Desktop.
Quick flask app to tell me if I can leave my window open...
#!/usr/bin/python
from flask import Flask, render_template
app = Flask(__name__)
import os
import json
import nest
from nest import utils as nest_utils
import subprocess
allowable_humidity=90
evaluate_hours=12
rain_signs=["Light Rain", "Rain", "Drizzle"]
nest_username = 'nestusername@email.com'
nest_password = 'password'
@app.route('/')
def check_weather():
output=subprocess.check_output(["weather-cli", "-h","--format","json"])
parsed_output=json.loads(output)
# Calling the NEST API here.
napi = nest.Nest(nest_username, nest_password)
for structure in napi.structures:
current_temp=nest_utils.c_to_f(structure.devices[1].target)
# If you don't have a NEST just uncomment the next line and remove the 3 lines above.
# current_temp=75
#Running Max(es)
max_temp=-100
max_humidity=0
rain=False
full_output=[]
count = 0
for row in parsed_output['table']:
count +=1
if count == 1: continue
elif count == evaluate_hours+2: break
temp = (1.8 * float(row[3][:-2])) + 32
# print " time: " + row[0] +" conditions: " + row[1] + " feels like: " + str(temp) + " humidity: " + row[4]
full_output.append({"time":row[0],"conditions":row[1],"temp":str(temp),"humidity":row[4]})
if row[1] in rain_signs: rain=True
if temp > max_temp: max_temp = temp
if int(row[4][:-1]) > max_humidity: max_humidity = int(row[4][:-1])
# print "\nMax Temp: " + str(max_temp)
# print "Max Humidity: " + str(max_humidity)
# print "Rain?: " + str(rain)
window_open = True
if max_temp > current_temp: window_open=False
if max_humidity > allowable_humidity: window_open=False
if rain: window_open=False
return render_template('index.html',
window_open=window_open,
current_temp=current_temp,
max_temp=max_temp,
max_humidity=max_humidity,
rain=rain,
evaluate_hours=evaluate_hours,
full_output=full_output,)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment