This commit is contained in:
yukivachot@gmail.com 2021-10-18 15:22:27 +02:00
parent 20f5cc55ac
commit 1d2bb73082
2 changed files with 31 additions and 5 deletions

31
app.py
View file

@ -2,6 +2,9 @@ import os
import sys import sys
from flask import Flask, request, render_template 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 contextlib import closing
from urllib.request import urlopen from urllib.request import urlopen
import json import json
@ -14,6 +17,17 @@ def log(*args):
sys.stdout.flush() 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): def getApiCity(search):
if METEOCONCEPT_TOKEN is None: if METEOCONCEPT_TOKEN is None:
log('Env variable METEOCONCEPT_TOKEN not passed') log('Env variable METEOCONCEPT_TOKEN not passed')
@ -85,9 +99,19 @@ def index():
response_cities = False response_cities = False
response_ephemeride = False response_ephemeride = False
response_around = False response_around = False
if request.method == 'POST':
search = request.form['search'] search = Search()
response_cities = getApiCity(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 ? # TODO Multiple form for insee ? or ajax ?
# insee = request.form['insee'] # insee = request.form['insee']
@ -144,4 +168,5 @@ if __name__ == '__main__':
# On Linux or MAC 'export METEOCONCEPT_TOKEN=...' (check shell echo $METEOCONCEPT_TOKEN) # On Linux or MAC 'export METEOCONCEPT_TOKEN=...' (check shell echo $METEOCONCEPT_TOKEN)
# On Windows 'set METEOCONCEPT_TOKEN=...' (check on Powershell echo $Env:METEOCONCEPT_TOKEN) # On Windows 'set METEOCONCEPT_TOKEN=...' (check on Powershell echo $Env:METEOCONCEPT_TOKEN)
METEOCONCEPT_TOKEN = os.environ.get('METEOCONCEPT_TOKEN', None) METEOCONCEPT_TOKEN = os.environ.get('METEOCONCEPT_TOKEN', None)
app.config['SECRET_KEY'] = 'secret_key'
app.run(host='0.0.0.0', port=PORT, debug=True) app.run(host='0.0.0.0', port=PORT, debug=True)

View file

@ -1 +1,2 @@
Flask_WTF==0.15.1
Flask==2.0.2 Flask==2.0.2