This commit is contained in:
yukivachot@gmail.com 2021-11-08 15:31:39 +01:00
parent 1d2bb73082
commit f6a26e7a37
4 changed files with 142 additions and 135 deletions

36
app.py
View file

@ -1,32 +1,12 @@
import os import os
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
from config import * from config import *
from forms import *
# logging helper
def log(*args):
print(args[0] % (len(args) > 1 and args[1:] or []))
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:
@ -104,19 +84,19 @@ def index():
city = City() city = City()
around = Around() around = Around()
if search.validate_on_submit(): if search.submit_search.data and search.validate_on_submit():
return render_template('index.html', cities=getApiCity(search)) return render_template('index.html', cities=getApiCity(search))
if city.validate_on_submit(): if city.submit_city.data and city.validate_on_submit():
return render_template('index.html', ephemeride=getEphemeride(city)) return render_template('index.html', ephemeride=getEphemeride(city))
if around.validate_on_submit(): if around.submit_around.data and around.validate_on_submit():
return render_template('index.html', around=getAround(around, 1)) 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']
# response_ephemeride = getEphemeride(insee) response_ephemeride = getEphemeride(insee)
# response_around = getAround(insee, 1) response_around = getAround(insee, 1)
return render_template('index.html', cities=response_cities, ephemeride=response_ephemeride, around=response_around) return render_template('index.html', cities=response_cities, ephemeride=response_ephemeride, around=response_around)

View file

@ -1,3 +1,12 @@
import sys
# logging helper
def log(*args):
print(args[0] % (len(args) > 1 and args[1:] or []))
sys.stdout.flush()
# JSON DUMPS # JSON DUMPS
INDENT = 4 INDENT = 4

18
forms.py Normal file
View file

@ -0,0 +1,18 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, validators
from wtforms.validators import InputRequired
class Search(FlaskForm):
search = StringField('Search', [validators.InputRequired()])
submit_search = SubmitField('submit')
class City(FlaskForm):
insee = StringField('Insee', [validators.InputRequired()])
submit_city = SubmitField('submit')
class Around(FlaskForm):
insee = StringField('Insee', [validators.InputRequired()])
submit_around = SubmitField('submit')