Merge pull request #8 from altf4arnold/Timezone

Timezone
This commit is contained in:
Arnold Dechamps 2024-03-20 03:19:18 +01:00 committed by GitHub
commit 1bce629e3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 8 deletions

11
app.py
View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -15,14 +15,22 @@
<th>Destination</th>
<th>Remarks</th>
</tr>
{% for flight in data%}
{% for flight in data %}
<tr>
<td>{{ flight["ident"] }}</td>
<td>{{ flight["scheduled_off"] }}</td>
<td>{{ flight["departure_delay"] }}</td>
<td>{{ flight["operator"] }}</td>
<td>{{ flight["destination"]["name"] }}</td>
<td>{{ flight["status"] }}</td>
<td>{{ flight["ident"] }}</td>
<td>{{ flight["scheduled_off"] }}</td>
<td>{% if flight["departure_delay"] %}
{{ flight["departure_delay"] }}
{% else %}
{% endif %}
</td>
<td>{{ flight["operator"] }}</td>
<td>{{ flight["destination"]["name"] }}</td>
<td>{% if flight["status"] != "Scheduled" %}
{{ flight["status"] }}
{% else %}
{% endif %}
</td>
</tr>
{% endfor %}
</table>