From a180387cf46511976d6e1ebbcdab672eeed2a572 Mon Sep 17 00:00:00 2001 From: altf4arnold Date: Wed, 20 Mar 2024 02:59:05 +0100 Subject: [PATCH 1/2] converts from UTC-TIME to Local Airport time (based on airport info from API) --- app.py | 11 +++++++++++ requirements.in | 3 +++ requirements.txt | 10 +++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 202a898..c7b2acb 100644 --- a/app.py +++ b/app.py @@ -5,13 +5,24 @@ This piece of code was written by myself. Supposed to be a frontend for a web-pa import datapull from flask import Flask, render_template from config import AIRPORT as airport +from datetime import datetime +from dateutil import tz app = Flask(__name__) @app.route("/") def hello_world(): + localformat = "%H:%M" rawdata = datapull.grabber() + for flight in rawdata: + origintimezone = flight["origin"]["timezone"] + from_zone = tz.gettz('UTC') + to_zone = tz.gettz(origintimezone) + utctime = datetime.strptime(flight["scheduled_off"], "%Y-%m-%dT%H:%M:%SZ") + utctime = utctime.replace(tzinfo=from_zone) + flight["scheduled_off"] = utctime.astimezone(to_zone).strftime(localformat) + return render_template('screen.html', airport=airport, data=rawdata) diff --git a/requirements.in b/requirements.in index 78466f6..8cab72d 100644 --- a/requirements.in +++ b/requirements.in @@ -4,9 +4,12 @@ charset-normalizer==3.3.2 click==8.1.7 Flask==3.0.2 idna==3.6 +install==1.3.5 itsdangerous==2.1.2 Jinja2==3.1.3 MarkupSafe==2.1.5 +python-dateutil==2.9.0.post0 requests==2.31.0 +six==1.16.0 urllib3==2.2.1 Werkzeug==3.0.1 diff --git a/requirements.txt b/requirements.txt index a2e7129..ef511b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.12 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --output-file=requirements.txt requirements.in @@ -26,6 +26,8 @@ idna==3.6 # via # -r requirements.in # requests +install==1.3.5 + # via -r requirements.in itsdangerous==2.1.2 # via # -r requirements.in @@ -39,8 +41,14 @@ markupsafe==2.1.5 # -r requirements.in # jinja2 # werkzeug +python-dateutil==2.9.0.post0 + # via -r requirements.in requests==2.31.0 # via -r requirements.in +six==1.16.0 + # via + # -r requirements.in + # python-dateutil urllib3==2.2.1 # via # -r requirements.in From ef1ac127b0341418a00bb9cda9969b7a33bc87ec Mon Sep 17 00:00:00 2001 From: altf4arnold Date: Wed, 20 Mar 2024 03:17:38 +0100 Subject: [PATCH 2/2] deleting scheduled and None/0 from the page --- templates/screen.html | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/templates/screen.html b/templates/screen.html index d41c133..497c61d 100644 --- a/templates/screen.html +++ b/templates/screen.html @@ -15,14 +15,22 @@ Destination Remarks - {% for flight in data%} + {% for flight in data %} - {{ flight["ident"] }} - {{ flight["scheduled_off"] }} - {{ flight["departure_delay"] }} - {{ flight["operator"] }} - {{ flight["destination"]["name"] }} - {{ flight["status"] }} + {{ flight["ident"] }} + {{ flight["scheduled_off"] }} + {% if flight["departure_delay"] %} + {{ flight["departure_delay"] }} + {% else %} + {% endif %} + + {{ flight["operator"] }} + {{ flight["destination"]["name"] }} + {% if flight["status"] != "Scheduled" %} + {{ flight["status"] }} + {% else %} + {% endif %} + {% endfor %}