-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
130 lines (113 loc) · 3.37 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import os
import arrow
from flask import render_template, jsonify, request, make_response
from flaskapp import app
from funcs import *
from models import *
from fetchConditions import loadCurrentConditions
from fetchForecast import loadForecast
'''
when: 2016-01-16 07:35:47+00:00
uv: 0
solarradiation: None
visibility: 16.1
winddir: 16
winddeg: 4
windspeed: 0.0
windgust: 1.9
rainamt_prev: 0
rainamt: 0
rainrate: 0
'''
def getCurrentConditions():
return loadCurrentConditions()
# ajax func - to be used to update periodically via jquery
@app.route('/lastupdate/')
def lastUpdate():
cond = getCurrentConditions()
return getTime(cond.when)
@app.route('/temperature/')
def currTemp():
cond = getCurrentConditions()
return jsonify(
temperature=cond.getTemperature(),
humidity = cond.humidity,
heatindex = cond.getHeatIndex(),
windchill = cond.getWindChill(),
feel = cond.getRealFeel(),
dewpoint = cond.getDewpoint(),
rawdp = cond.getRawDewpoint()
)
@app.route('/outlook/')
def outlook():
cond = getCurrentConditions()
pressTrend = cond.pressureTrend
if pressTrend >= 0:
pressTrend = '+%s' % pressTrend
return jsonify(
icon=cond.getIconUrl(),
outlook = cond.outlook,
pressure = cond.pressure,
presstrend = pressTrend,
)
@app.route('/wind/')
def wind():
cond = getCurrentConditions()
currdir = cond.getWindDirection()
mindir, maxdir = cond.getWindDirRange()
return jsonify(
currdir=currdir,
mindir = mindir,
maxdir = maxdir,
speed = cond.getWindSpeed(),
gusts = cond.getWindGust(),
)
@app.route('/rain/')
def rain():
cond = getCurrentConditions()
return jsonify(
ratewg = getDistInUnits(cond.rainrate),
rate = getDistInUnits(cond.getRainRate()),
amt = getDistInUnits(cond.rainamt),
)
@app.route('/hilo_temps/')
def hilow_temps():
forecast = loadForecast()
past1 = forecast.pastTemps[0]
past2 = forecast.pastTemps[1]
future1 = forecast.futureTemps[0]
future2 = forecast.futureTemps[1]
return jsonify(
past1_label = past1.getLabel(),
past1_value = past1.getValue(),
past2_label = past2.getLabel(),
past2_value = past2.getValue(),
future1_label = future1.getLabel(),
future1_value = future1.getValue(),
future2_label = future2.getLabel(),
future2_value = future2.getValue(),
)
@app.route('/setunits/')
def setUnits():
"Save post data for user preferred units"
"See - http://flask.pocoo.org/docs/0.10/quickstart/#cookies"
# resp = make_response(render_template(...))
# resp.set_cookie('units_timp', unitsTemp)
# return resp
pass
@app.route('/')
def index():
cond = getCurrentConditions()
url = '{root}{key}/animatedradar/q/{loc}.gif?newmaps=1&rainsnow=1&radius=70&timelabel=1&timelabel.x=200&timelabel.y=20'.format(root=app.config['WUG_ROOT'],
key=app.config['WUG_KEY'],
loc=app.config['LOCATION'])
return render_template('index.html',
#TODO - get rid of metric:
metric = cond.metric,
units_temp = getUnitsTemp(),
units_dist = getUnitsDist(),
units_speed = getUnitsSpeed(),
units_pressure = getUnitsPressure(),
hot = True if CtoF(cond.temperature) >= 75 else False,
map_url = url,
)