From dbc4ce3229becf44881c955e8bee063f4730d793 Mon Sep 17 00:00:00 2001 From: altf4arnold Date: Wed, 20 Mar 2024 01:56:43 +0100 Subject: [PATCH 1/4] first try at flask --- datapull.py | 4 ++-- server.py | 19 +++++++++++++++++++ static/style.css | 0 templates/screen.html | 29 +++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 server.py create mode 100644 static/style.css create mode 100644 templates/screen.html diff --git a/datapull.py b/datapull.py index 276093d..eba4bbf 100644 --- a/datapull.py +++ b/datapull.py @@ -5,7 +5,7 @@ import config import requests -def main(): +def grabber(): """ Main function to pull data from flightaware API. Mostly flightaware code with overhead. Will modify if needed :return: raw data @@ -27,7 +27,7 @@ def main(): if __name__ == '__main__': - departures = main() + departures = grabber() name = "unknown" operator = "unknown" scheduled_off = "unknown" diff --git a/server.py b/server.py new file mode 100644 index 0000000..ad7cbe9 --- /dev/null +++ b/server.py @@ -0,0 +1,19 @@ +""" +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 config import AIRPORT as airport + +app = Flask(__name__) +@app.route("/") +def hello_world(): + rawdata = datapull.grabber() + return render_template('screen.html', airport=airport, data=rawdata) + + +@app.route("/style.css") +def style(): + with open("static/style.css", "r") as f: + return f.read(), 200, {'Content-Type': 'text/css; charset=utf-8'} \ No newline at end of file diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..e69de29 diff --git a/templates/screen.html b/templates/screen.html new file mode 100644 index 0000000..a3ce38b --- /dev/null +++ b/templates/screen.html @@ -0,0 +1,29 @@ + + + + + {{ airport }} Departure Schedule + + + + + + + + + + + + {% for flight in data%} + + + + + + + + + {% endfor %} +
FlightTimeDelayAirlineDestinationRemarks
{{ flight["ident"] }}{{ flight["scheduled_off"] }}{{ flight["departure_delay"] }}{{ flight["operator"] }}{{ flight["destination"]["name"] }}{{ flight["status"] }}
+ + \ No newline at end of file From 0018e0542fbc587347bfca67ec4532cf1cb859bb Mon Sep 17 00:00:00 2001 From: altf4arnold Date: Wed, 20 Mar 2024 02:01:06 +0100 Subject: [PATCH 2/4] adding the link to the CSS file --- templates/screen.html | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/screen.html b/templates/screen.html index a3ce38b..d41c133 100644 --- a/templates/screen.html +++ b/templates/screen.html @@ -2,6 +2,7 @@ + {{ airport }} Departure Schedule From 1db76a8ab0c23063c8fe742ac73f48c33711d3a1 Mon Sep 17 00:00:00 2001 From: altf4arnold Date: Wed, 20 Mar 2024 02:05:18 +0100 Subject: [PATCH 3/4] README and files --- README.md | 9 ++++++++- server.py => app.py | 0 2 files changed, 8 insertions(+), 1 deletion(-) rename server.py => app.py (100%) diff --git a/README.md b/README.md index a594b3d..7156b19 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,11 @@ This program uses the API of Flightaware. Said API requires an API key. More info [here](https://www.flightaware.com/commercial/aeroapi) # Config.py : -The example file needs to be copied as config.py. There, you can configure the API key and airport that interests you. \ No newline at end of file +The example file needs to be copied as config.py. There, you can configure the API key and airport that interests you. + +# datapull.py : +This file will pull the data from flightaware's server and print it on the terminal + +# Flask : +To start flask, ``flask run`` +You can then go on ``https://127.0.0.1:5000`` \ No newline at end of file diff --git a/server.py b/app.py similarity index 100% rename from server.py rename to app.py From be1490960166e8a35b076235abe60961e754a055 Mon Sep 17 00:00:00 2001 From: altf4arnold Date: Wed, 20 Mar 2024 02:06:52 +0100 Subject: [PATCH 4/4] Flake8 not happy --- app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index ad7cbe9..202a898 100644 --- a/app.py +++ b/app.py @@ -7,6 +7,8 @@ from flask import Flask, render_template from config import AIRPORT as airport app = Flask(__name__) + + @app.route("/") def hello_world(): rawdata = datapull.grabber() @@ -16,4 +18,4 @@ def hello_world(): @app.route("/style.css") def style(): with open("static/style.css", "r") as f: - return f.read(), 200, {'Content-Type': 'text/css; charset=utf-8'} \ No newline at end of file + return f.read(), 200, {'Content-Type': 'text/css; charset=utf-8'}