From 27ea40e7379d07427cd36fe24a4e334af07790fd Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Wed, 6 Oct 2021 09:11:22 +0200 Subject: [PATCH] Add bus time to line JSON --- buscribe-api/buscribeapi/buscribeapi.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/buscribe-api/buscribeapi/buscribeapi.py b/buscribe-api/buscribeapi/buscribeapi.py index a1b7a2b..bcee39b 100644 --- a/buscribe-api/buscribeapi/buscribeapi.py +++ b/buscribe-api/buscribeapi/buscribeapi.py @@ -13,6 +13,9 @@ app = flask.Flask('buscribe') def convert_vtt_timedelta(delta: timedelta): return f'{delta.days * 24 + delta.seconds // 3600:02}:{(delta.seconds % 3600) // 60:02}:{delta.seconds % 60:02}.{delta.microseconds // 1000:03}' +def round_bus_time(delta: timedelta): + """Round bus time down to the second.""" + return f'{delta.days * 24 + delta.seconds // 3600:02}:{(delta.seconds % 3600) // 60:02}:{delta.seconds % 60:02}' @app.route('/buscribe/vtt') def get_vtt(): @@ -81,7 +84,9 @@ def get_json(): results = fetch_lines(db_conn, start_time, end_time, query) return jsonify([{"start_time": row.start_time.isoformat(), + "start_bus_time": round_bus_time(row.start_time - app.bustime_start), "end_time": row.end_time.isoformat(), + "end_bus_time": round_bus_time(row.start_time - app.bustime_start), "text": row.transcription_line} for row in results])