Update
This commit is contained in:
parent
20f5cc55ac
commit
1d2bb73082
2 changed files with 31 additions and 5 deletions
33
app.py
33
app.py
|
|
@ -2,6 +2,9 @@ import os
|
|||
import sys
|
||||
|
||||
from flask import Flask, request, render_template
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, IntegerField, FloatField, validators
|
||||
from wtforms.validators import InputRequired
|
||||
from contextlib import closing
|
||||
from urllib.request import urlopen
|
||||
import json
|
||||
|
|
@ -14,6 +17,17 @@ def log(*args):
|
|||
sys.stdout.flush()
|
||||
|
||||
|
||||
class Search(FlaskForm):
|
||||
search = StringField('Search', [validators.InputRequired()])
|
||||
|
||||
|
||||
class City(FlaskForm):
|
||||
insee = StringField('Insee', [validators.InputRequired()])
|
||||
|
||||
|
||||
class Around(FlaskForm):
|
||||
insee = StringField('Insee', [validators.InputRequired()])
|
||||
|
||||
def getApiCity(search):
|
||||
if METEOCONCEPT_TOKEN is None:
|
||||
log('Env variable METEOCONCEPT_TOKEN not passed')
|
||||
|
|
@ -85,9 +99,19 @@ def index():
|
|||
response_cities = False
|
||||
response_ephemeride = False
|
||||
response_around = False
|
||||
if request.method == 'POST':
|
||||
search = request.form['search']
|
||||
response_cities = getApiCity(search)
|
||||
|
||||
search = Search()
|
||||
city = City()
|
||||
around = Around()
|
||||
|
||||
if search.validate_on_submit():
|
||||
return render_template('index.html', cities=getApiCity(search))
|
||||
|
||||
if city.validate_on_submit():
|
||||
return render_template('index.html', ephemeride=getEphemeride(city))
|
||||
|
||||
if around.validate_on_submit():
|
||||
return render_template('index.html', around=getAround(around, 1))
|
||||
|
||||
# TODO Multiple form for insee ? or ajax ?
|
||||
# insee = request.form['insee']
|
||||
|
|
@ -144,4 +168,5 @@ if __name__ == '__main__':
|
|||
# On Linux or MAC 'export METEOCONCEPT_TOKEN=...' (check shell echo $METEOCONCEPT_TOKEN)
|
||||
# On Windows 'set METEOCONCEPT_TOKEN=...' (check on Powershell echo $Env:METEOCONCEPT_TOKEN)
|
||||
METEOCONCEPT_TOKEN = os.environ.get('METEOCONCEPT_TOKEN', None)
|
||||
app.run(host='0.0.0.0', port=PORT, debug=True)
|
||||
app.config['SECRET_KEY'] = 'secret_key'
|
||||
app.run(host='0.0.0.0', port=PORT, debug=True)
|
||||
Loading…
Add table
Add a link
Reference in a new issue