From b170557b2401425a185df64a9caf09099b45f96a Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sun, 12 Feb 2023 23:09:20 +0100 Subject: [PATCH] Add form with autocompletion for origin, destination and date --- .gitignore | 1 + app.py | 26 +++++++++++++-- templates/index.html | 79 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 templates/index.html diff --git a/.gitignore b/.gitignore index 8bde042..49d0227 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__ .idea env venv +.env instance/ config.py diff --git a/app.py b/app.py index a771fdc..6291267 100644 --- a/app.py +++ b/app.py @@ -8,7 +8,7 @@ from pytz import timezone import requests import click -from flask import Flask +from flask import Flask, render_template from flask.cli import AppGroup from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy @@ -230,6 +230,14 @@ def queue_route(day: date | datetime, origin: str, destination: str): print("Already queued") return + query = db.session.query(RouteQueue).filter(RouteQueue.day == day, + RouteQueue.origin == origin, + RouteQueue.destination == destination, + RouteQueue.expiration_time >= datetime.now(timezone('UTC'))) + if query.count(): + print("Using recent value") + return + db.session.add(RouteQueue(day=day, origin=origin, destination=destination)) db.session.commit() @@ -282,7 +290,21 @@ def process_queue(number: int): @app.get('/') def index(): - return "Hello world!" + return render_template('index.html', today=date.today(), max_day=date.today() + timedelta(days=30)) + + +@cli.command('test') +@app.get('/api/iata-codes/') +def iata_codes(): + query = db.session.query(Train).with_entities(Train.orig_iata, Train.orig).distinct() + return { + 'iata2name': { + k: v for (k, v) in query.all() + }, + 'name2iata': { + v: k for (k, v) in query.all() + } + } if __name__ == '__main__': diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..f271e07 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,79 @@ + + + + Calculateur TGVMax + + + +
+ + +
+ + + +
Le point de départ de votre trajet.
+
+
+ + + +
Le point d'arrivée de votre trajet.
+
+
+ + +
Le jour de votre départ.
+
+
+ +
+
+ + + + +