From 22e270b6ffc37cc74eb95699e2fc118546926e38 Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Mon, 8 Nov 2021 17:47:31 +0100 Subject: [PATCH] #4 Add bustime search options --- buscribe-api/buscribeapi/buscribeapi.py | 14 ++++++++++++- buscribe-web/form.less | 7 +++++++ buscribe-web/index.html | 28 ++++++++++++++++--------- buscribe-web/script.js | 16 ++++++++++++-- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/buscribe-api/buscribeapi/buscribeapi.py b/buscribe-api/buscribeapi/buscribeapi.py index a5b847d..4d38718 100644 --- a/buscribe-api/buscribeapi/buscribeapi.py +++ b/buscribe-api/buscribeapi/buscribeapi.py @@ -2,7 +2,7 @@ from datetime import timedelta import common import flask as flask -from common import dateutil, database, format_bustime, dt_to_bustime +from common import dateutil, database, format_bustime, dt_to_bustime, bustime_to_dt, parse_bustime from dateutil.parser import ParserError from flask import request, jsonify, Response, render_template @@ -68,20 +68,32 @@ def get_json(): (https://www.postgresql.org/docs/13/functions-textsearch.html)""" start_time_string = request.args.get('start_time') + bus_start_time_string = request.args.get('bus_start_time') if start_time_string is not None: try: start_time = dateutil.parse(start_time_string) except ParserError: return "Invalid start time!", 400 + elif bus_start_time_string is not None: + try: + start_time = bustime_to_dt(app.bustime_start, parse_bustime(bus_start_time_string)) + except ValueError: + return "Invalid bus end time!", 400 else: start_time = None end_time_string = request.args.get('end_time') + bus_end_time_string = request.args.get('bus_end_time') if end_time_string is not None: try: end_time = dateutil.parse(end_time_string) except ParserError: return "Invalid end time!", 400 + elif bus_end_time_string is not None: + try: + end_time = bustime_to_dt(app.bustime_start, parse_bustime(bus_end_time_string)) + except ValueError: + return "Invalid bus end time!", 400 else: end_time = None diff --git a/buscribe-web/form.less b/buscribe-web/form.less index 87b1cac..0100603 100644 --- a/buscribe-web/form.less +++ b/buscribe-web/form.less @@ -6,6 +6,12 @@ margin-bottom: 1em; + div { + margin: 0; + padding: 0; + display: flex; + } + label { display: inline-block; font-family: @sans-serif; @@ -29,6 +35,7 @@ #time_search_line { display: flex; flex-direction: row; + flex-wrap: wrap; input[type=datetime-local] { width: 13em; diff --git a/buscribe-web/index.html b/buscribe-web/index.html index 1161146..bc6adb7 100644 --- a/buscribe-web/index.html +++ b/buscribe-web/index.html @@ -9,18 +9,26 @@