Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3.  
  4. from flask import Flask, render_template
  5. app = Flask(__name__)
  6.  
  7. import os
  8. import json
  9. import nest
  10. from nest import utils as nest_utils
  11. import subprocess
  12.  
  13. allowable_humidity=90
  14. evaluate_hours=12
  15. rain_signs=["Light Rain", "Rain", "Drizzle"]
  16.  
  17.  
  18. nest_username = 'nestusername@email.com'
  19. nest_password = 'password'
  20.  
  21. @app.route('/')
  22. def check_weather():
  23. output=subprocess.check_output(["weather-cli", "-h","--format","json"])
  24. parsed_output=json.loads(output)
  25.  
  26. napi = nest.Nest(nest_username, nest_password)
  27. for structure in napi.structures:
  28. current_temp=nest_utils.c_to_f(structure.devices[1].target)
  29.  
  30.  
  31. #Running Max(es)
  32. max_temp=-100
  33. max_humidity=0
  34. rain=False
  35.  
  36. full_output=[]
  37. count = 0
  38. for row in parsed_output['table']:
  39. count +=1
  40. if count == 1: continue
  41. elif count == evaluate_hours+2: break
  42. temp = (1.8 * float(row[3][:-2])) + 32
  43. # print " time: " + row[0] +" conditions: " + row[1] + " feels like: " + str(temp) + " humidity: " + row[4]
  44. full_output.append({"time":row[0],"conditions":row[1],"temp":str(temp),"humidity":row[4]})
  45. if row[1] in rain_signs: rain=True
  46. if temp > max_temp: max_temp = temp
  47. if int(row[4][:-1]) > max_humidity: max_humidity = int(row[4][:-1])
  48.  
  49. # print "\nMax Temp: " + str(max_temp)
  50. # print "Max Humidity: " + str(max_humidity)
  51. # print "Rain?: " + str(rain)
  52.  
  53. window_open = True
  54. if max_temp > current_temp: window_open=False
  55. if max_humidity > allowable_humidity: window_open=False
  56. if rain: window_open=False
  57.  
  58. return render_template('index.html',
  59. window_open=window_open,
  60. current_temp=current_temp,
  61. max_temp=max_temp,
  62. max_humidity=max_humidity,
  63. rain=rain,
  64. evaluate_hours=evaluate_hours,
  65. full_output=full_output,)
  66.  
  67.  
  68. if __name__ == "__main__":
  69. app.run(host='0.0.0.0', port=80)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement