in cloud-run-alwayson-cpu-weather-advisory/python/main.py [0:0]
def root():
'main application handler (GET/POST)'
context = {'meth': request.method, 'state': DEFAULT}
# GET: render empty form
# POST: process user request, display results, render empty form
if request.method == 'POST':
try:
state = request.form['state'].strip()[:2].upper() or DEFAULT
context['state'] = state
processState(state)
stateData = getStateFromCache(state)
if stateData:
context['advs'] = stateData['advisories']
else:
context['error'] = 'ERROR: problem with request for {%s}' % state
except Exception as e:
error = 'ERROR: problem with request for %s: %s' % (state, e)
print(error)
context['error'] = error
return render_template('index.html', **context)