-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
53 lines (47 loc) · 2.02 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
This piece of code was written by myself. Supposed to be a frontend for a web-page that will run on a raspi in kiosk mode
"""
import datapull
from flask import Flask, render_template
from datetime import datetime, timedelta
from dateutil import tz
app = Flask(__name__)
@app.route("/")
def hello_world():
localformat = "%H:%M"
rawdata = datapull.grabber()
airport = {"name": "", "icao": "", "iata": ""}
for flight in rawdata:
# Source Airport naming :
airport["name"] = flight["origin"]["name"]
airport["icao"] = flight["origin"]["code_icao"]
airport["iata"] = flight["origin"]["code_iata"]
# Converting departures time from UTC to local time :
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)
# Adding the secondary flight numbers :
flightnr = flight["ident"]
flight["ident"] = []
flight["ident"].append(flightnr)
for otherrefs in flight["codeshares"]:
flight["ident"].append(otherrefs)
# Calculating Delays in human readable ways :
negative = False
delay = flight["departure_delay"]
if delay != 0:
if delay is not None:
# taking advances in account
if delay < 0:
# delay is negative
negative = True
delay = abs(delay)
delay = timedelta(seconds=delay)
delay = datetime.strptime(str(delay), "%H:%M:%S")
flight["departure_delay"] = delay.strftime(localformat)
if negative:
flight["departure_delay"] = ("-" + str(flight["departure_delay"]))
return render_template('screen.html', len=len(rawdata), airport=airport, flight=rawdata)