From ce41b31331a8bbf78fe657f8e037016407743219 Mon Sep 17 00:00:00 2001 From: te5154c Date: Tue, 27 Feb 2024 23:58:57 +0300 Subject: [PATCH 1/2] hotfix: userid --- README.md | 4 +++- src/app.py | 7 +++++-- src/static/viewer.js | 8 ++++---- src/templates/include/template.html | 16 ++++++++-------- src/templates/viewer.html | 10 +++++----- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e8cef61..7427381 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

-

VATSIM Fox

+

VATSIM Fox — v1.2

Website to find out your detailed VATSIM stastic


@@ -37,6 +37,8 @@ python -m venv venv # downloading requirements && upgrading pip python -m pip install --upgrade pip python -m pip install -r requirements.txt +# starting application +python -m flask run --host 0.0.0.0 --debug ``` ## Feature diff --git a/src/app.py b/src/app.py index 00d3658..602bb13 100644 --- a/src/app.py +++ b/src/app.py @@ -19,7 +19,10 @@ def errorhandler_page(_): @app.route("/api/request") def request_handler(): if request_string := request.args.get("request_string"): - return requests.get(f"{VATSIM_API_URL}{request_string}").json() + try: + return requests.get(f"{VATSIM_API_URL}{request_string}").json() + except requests.exceptions.JSONDecodeError: + return jsonify({"result": "not found"}) return jsonify({"result": "not found"}) @@ -31,7 +34,7 @@ def viewer_page(cid): if "detail" in user and user["detail"] == "Not Found": return abort(404) - return render_template("viewer.html", data=(user, )) + return render_template("viewer.html", user=user) if __name__ == "__main__": diff --git a/src/static/viewer.js b/src/static/viewer.js index 019fda0..42ea216 100644 --- a/src/static/viewer.js +++ b/src/static/viewer.js @@ -72,13 +72,13 @@ $.getJSON("/static/data/airports.json", function(json) { // Map creation const MAP_ELEMENT = L.map("fox_map"); -const MAP_DEFAULT_TARGET = L.latLng("47.50737", "19.04611"); -const MAP_DEFAULT_ZOOM_VIEW = 14; +const MAP_DEFAULT_ZOOM_VIEW = 2; +const MAP_DEFAULT_TARGET = L.latLng("0", "0"); let line = null; MAP_ELEMENT.setView(MAP_DEFAULT_TARGET, MAP_DEFAULT_ZOOM_VIEW); -L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", { +L.tileLayer("https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png", { attribution: '© OpenStreetMap contributors', subdomains: "abcd", maxZoom: 20, @@ -143,7 +143,7 @@ function showFlight(flight) { // Function to show ATC session function showSession(session) { if (!session) return; - + console.log(session); $(".atc_callsign").text(session["connection_id"]["callsign"]); $(".atc_start_time").text(session["connection_id"]["start"].replace("T", " ")); $(".atc_end_time").text(session["connection_id"]["end"].replace("T", " ")); diff --git a/src/templates/include/template.html b/src/templates/include/template.html index ed73ee1..ae3a9e5 100644 --- a/src/templates/include/template.html +++ b/src/templates/include/template.html @@ -19,7 +19,7 @@ @@ -33,13 +33,13 @@ {% block content %}{% endblock %} - - - + + + - - {% block javascript_code %}{% endblock %} + + {% block javascript_code %}{% endblock %} \ No newline at end of file diff --git a/src/templates/viewer.html b/src/templates/viewer.html index afdbd9e..601fb3b 100644 --- a/src/templates/viewer.html +++ b/src/templates/viewer.html @@ -1,12 +1,12 @@ {% extends "/include/template.html" %} -{% block title %}User {{user_cid}} statistic — VATSIM Fox{% endblock %} +{% block title %}User {{user["id"]}} statistic — VATSIM Fox{% endblock %} {% block header_css %} {% endblock %} {% block content %}
-

{{data[0]["id"]}}

+

{{user["id"]}}

Date of registration:

@@ -91,7 +91,7 @@
-

UUEE_DEL

+

Callsign

Start time: @@ -133,11 +133,11 @@ {% block javascript_code %} {% endblock %} From bc8ca017290af4128df730be63e151a73112e53a Mon Sep 17 00:00:00 2001 From: te5154c Date: Wed, 28 Feb 2024 00:45:17 +0300 Subject: [PATCH 2/2] add: notification in viewer when error appears && api requests exception && new map-style (preparing for new update) && buttons color change --- README.md | 2 +- src/app.py | 4 ++-- src/static/viewer.css | 4 ++++ src/static/viewer.js | 14 +++++++++++--- src/templates/include/template.html | 12 ++++++++++++ src/templates/index.html | 2 +- src/templates/viewer.html | 7 +++++++ 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7427381..0ecb0db 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Project based on [Virtual Air Traffic Simulation Network (VATSIM) API](https://v Written in Python 3.8.18 + JS (JQuery framework) + Boostrap ## Startup -For run application on your own machine, you must install docker. Then just one command in the "src" folder with the project source code: +To run application on your own machine, you must install docker. Then just one command in the "src" folder with the project source code: ```bash docker compose up diff --git a/src/app.py b/src/app.py index 602bb13..dff3806 100644 --- a/src/app.py +++ b/src/app.py @@ -22,9 +22,9 @@ def request_handler(): try: return requests.get(f"{VATSIM_API_URL}{request_string}").json() except requests.exceptions.JSONDecodeError: - return jsonify({"result": "not found"}) + return jsonify({"result": "error", "message": "Something went wrong. Report that error please"}) - return jsonify({"result": "not found"}) + return jsonify({"result": "not found", "message": "Not found"}) @app.route("//") diff --git a/src/static/viewer.css b/src/static/viewer.css index c03c1cc..3220435 100644 --- a/src/static/viewer.css +++ b/src/static/viewer.css @@ -6,3 +6,7 @@ .fox_active, .fox_atc_active { background-color: #dee2e6 !important; } + +#notification_wrapper { + display: none; +} diff --git a/src/static/viewer.js b/src/static/viewer.js index 42ea216..8c0a63d 100644 --- a/src/static/viewer.js +++ b/src/static/viewer.js @@ -2,8 +2,10 @@ let userSession = {}; fetch(ATC_API_URL, {}).then(response => response.json()).then(result => { - if (result && result["result"] == "not found") - return + if (result && (result["result"] == "not found" || result["result"] == "error")) { + showAlert("Error while getting ATC information", result["message"]); + return; + } for (let session of result["items"]) { // Separate each session by it's connection ID @@ -143,7 +145,7 @@ function showFlight(flight) { // Function to show ATC session function showSession(session) { if (!session) return; - console.log(session); + $(".atc_callsign").text(session["connection_id"]["callsign"]); $(".atc_start_time").text(session["connection_id"]["start"].replace("T", " ")); $(".atc_end_time").text(session["connection_id"]["end"].replace("T", " ")); @@ -153,3 +155,9 @@ function showSession(session) { $(".atc_transfers").text(session["handoffsinitiated"]); $(".atc_received").text(session["handoffsreceived"]); } + +function showAlert(title, message) { + $("#notification_wrapper").css("display", "block"); + $("#notification_title").text(title); + $("#notification_message").text(message); +} diff --git a/src/templates/include/template.html b/src/templates/include/template.html index ae3a9e5..87bc675 100644 --- a/src/templates/include/template.html +++ b/src/templates/include/template.html @@ -18,7 +18,19 @@ {% block header_css %}{% endblock %} diff --git a/src/templates/index.html b/src/templates/index.html index e01fe89..7bb3f7c 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -7,7 +7,7 @@

See your detailed profile statistic

diff --git a/src/templates/viewer.html b/src/templates/viewer.html index 601fb3b..af2b9af 100644 --- a/src/templates/viewer.html +++ b/src/templates/viewer.html @@ -6,6 +6,13 @@ {% endblock %} {% block content %}
+
+ +
+

{{user["id"]}}

Date of registration: