From f5cac5e41086197ab608403ec746d9c38c698d60 Mon Sep 17 00:00:00 2001 From: te5154c Date: Mon, 5 Feb 2024 17:49:46 +0300 Subject: [PATCH 1/3] add: docker, fix: url to github in index.html & reqs.txt --- .dockerignore | 2 ++ .gitignore | 1 + Dockerfile | 12 ++++++++++++ app.py | 2 +- docker-compose.yml | 9 +++++++++ requirements.txt | 1 + templates/index.html | 2 +- 7 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1c2b579 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +media +README.md \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2e93279 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.7.10 + +WORKDIR /build/ + +COPY requirements.txt /build/ + +RUN pip install --upgrade pip +RUN pip install -r requirements.txt + +COPY . /build/ + +# CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] \ No newline at end of file diff --git a/app.py b/app.py index 684ca97..b97e7d8 100644 --- a/app.py +++ b/app.py @@ -26,4 +26,4 @@ def viewer_page(cid): if __name__ == "__main__": - app.run(debug=True) + app.run(host="0.0.0.0", port=80) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cdbb7e8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: "3" +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "80:5000" + network_mode: "host" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4b70123..3c767be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Flask==2.2.5 +requests==2.31.0 diff --git a/templates/index.html b/templates/index.html index 1482061..c2dc018 100644 --- a/templates/index.html +++ b/templates/index.html @@ -24,7 +24,7 @@

Open source project

This project is fully opened, so you can contribute in it if you want

- +
From e513a8499981483e127c6ace0d755da4006cb855 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 5 Feb 2024 22:09:26 +0700 Subject: [PATCH 2/3] fixed docker --- Dockerfile | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2e93279..dd45b5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,4 @@ RUN pip install -r requirements.txt COPY . /build/ -# CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] \ No newline at end of file +CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index cdbb7e8..4c96860 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,5 @@ version: "3" + services: app: build: @@ -6,4 +7,3 @@ services: dockerfile: Dockerfile ports: - "80:5000" - network_mode: "host" \ No newline at end of file From 0d481c4d6cd4a412c6a8dc2caab4e738b9f69abf Mon Sep 17 00:00:00 2001 From: te5154c Date: Mon, 5 Feb 2024 22:31:34 +0300 Subject: [PATCH 3/3] fixed: cors error (finnaly) && minor bugs, add: custom wrapper for VATSIM fetcher && code moved to src folder && docker --- LICENSE | 21 ++++++ README.md | 23 +++++-- .dockerignore => src/.dockerignore | 0 Dockerfile => src/Dockerfile | 0 app.py => src/app.py | 15 ++++- docker-compose.yml => src/docker-compose.yml | 0 requirements.txt => src/requirements.txt | 1 + {static => src/static}/data/airports.json | 0 {static => src/static}/icon.ico | Bin {static => src/static}/viewer.css | 0 {static => src/static}/viewer.js | 61 ++++++++++-------- {templates => src/templates}/4O4.html | 0 .../templates}/include/template.html | 0 {templates => src/templates}/index.html | 19 ++++-- {templates => src/templates}/viewer.html | 25 +++---- 15 files changed, 113 insertions(+), 52 deletions(-) create mode 100644 LICENSE rename .dockerignore => src/.dockerignore (100%) rename Dockerfile => src/Dockerfile (100%) rename app.py => src/app.py (50%) rename docker-compose.yml => src/docker-compose.yml (100%) rename requirements.txt => src/requirements.txt (68%) rename {static => src/static}/data/airports.json (100%) rename {static => src/static}/icon.ico (100%) rename {static => src/static}/viewer.css (100%) rename {static => src/static}/viewer.js (75%) rename {templates => src/templates}/4O4.html (100%) rename {templates => src/templates}/include/template.html (100%) rename {templates => src/templates}/index.html (70%) rename {templates => src/templates}/viewer.html (85%) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1dc0a3d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Mark + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 6ce6f47..0af8478 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,13 @@ Project based on [Virtual Air Traffic Simulation Network (VATSIM) API](https://v Written in Python 3.7.10 + 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: + +```bash +docker compose up +``` + ## Contibution Any help with this project would be greatly appreciated. Fixes or some features are welcome. @@ -21,13 +28,17 @@ More information about the contributing to this project will appear there a litt ## Feature There is small TODO list I would like to make in this project: -+ Deploy to webserver with domain -+ More ATC information — add map with control area -+ More profile information — add some more info, not only date of registration. Maybe rating or something -+ Website redesign -+ Challenges, like: "fly to this country N times", or "fly to all countries around the world", etc +- [x] Create docker +- [x] Deploy to webserver with domain +- [ ] More ATC information — add map with control area +- [ ] More profile information — add some more info, not only date of registration. Maybe rating or something +- [ ] Website redesign +- [ ] Challenges, like: "fly to this country N times", or "fly to all countries around the world", etc -## Author +## Contributors +https://github.com/exituser/ + +## Author contacts Telegram: https://uw935.t.me/
Instagram: https://instagram.com/uw_935/
Discord: uw935 \ No newline at end of file diff --git a/.dockerignore b/src/.dockerignore similarity index 100% rename from .dockerignore rename to src/.dockerignore diff --git a/Dockerfile b/src/Dockerfile similarity index 100% rename from Dockerfile rename to src/Dockerfile diff --git a/app.py b/src/app.py similarity index 50% rename from app.py rename to src/app.py index b97e7d8..9135d1e 100644 --- a/app.py +++ b/src/app.py @@ -1,8 +1,9 @@ -from flask import Flask, render_template, abort +from flask import Flask, render_template, abort, request, jsonify import requests app = Flask(__name__) +VATSIM_API_URL = "https://api.vatsim.net/v2/" @app.route("/") @@ -14,10 +15,20 @@ def index_page(): def errorhandler_page(_): return render_template("4O4.html"), 404 +# Custom wrapper to fetch VATSIM data +@app.route("/api/request") +def request_handler(): + request_string = request.args.get("request_string") + + if request_string: + return requests.get(f"{VATSIM_API_URL}{request_string}").json() + + return jsonify({"result": "not found"}) + @app.route("//") def viewer_page(cid): - user = requests.get(f"https://api.vatsim.net/v2/members/{cid}").json() + user = requests.get(f"{VATSIM_API_URL}members/{cid}").json() if "detail" in user and user["detail"] == "Not Found": return abort(404) diff --git a/docker-compose.yml b/src/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to src/docker-compose.yml diff --git a/requirements.txt b/src/requirements.txt similarity index 68% rename from requirements.txt rename to src/requirements.txt index 3c767be..560df14 100644 --- a/requirements.txt +++ b/src/requirements.txt @@ -1,2 +1,3 @@ Flask==2.2.5 requests==2.31.0 +flake8==5.0.4 diff --git a/static/data/airports.json b/src/static/data/airports.json similarity index 100% rename from static/data/airports.json rename to src/static/data/airports.json diff --git a/static/icon.ico b/src/static/icon.ico similarity index 100% rename from static/icon.ico rename to src/static/icon.ico diff --git a/static/viewer.css b/src/static/viewer.css similarity index 100% rename from static/viewer.css rename to src/static/viewer.css diff --git a/static/viewer.js b/src/static/viewer.js similarity index 75% rename from static/viewer.js rename to src/static/viewer.js index 349977f..89ed904 100644 --- a/static/viewer.js +++ b/src/static/viewer.js @@ -1,7 +1,10 @@ // Fetching user's ATC session informations from API let userSession = {}; -fetch(ATC_API_URL, {}).then(response => response.json).then(result => { +fetch(ATC_API_URL, {}).then(response => response.json()).then(result => { + if (result && result["result"] == "not found") + return + for (let session of result["items"]) { // Separate each session by it's connection ID let session_id = session["connection_id"]["id"]; @@ -13,24 +16,48 @@ fetch(ATC_API_URL, {}).then(response => response.json).then(result => { $("#fox_atc").append(sessionElement); } - showSession(userSession[result["items"][0]["callsign"]]); + // Click event handler to left menu button + $(".fox_atc").click(function() { + if ($(this).hasClass("fox_atc_active")) return; + + $(".fox_atc_active").removeClass("fox_atc_active"); + $(this).addClass("fox_atc_active"); + + showSession(userSession[$(this).attr("id")]); + }); + + showSession(result["items"][0]); }); // Fetching user's flightplans from VATSIM API let userFlightplans = {}; -fetch(FLIGHTPLANS_API_URL, {}).then(response => response.json).then(result => { +fetch(FLIGHTPLANS_API_URL, {}).then(response => response.json()).then(result => { + if (result && result["result"] == "not found") + return + for (let flightplan of result) { // Separate each flight by it's connection ID // Like it was with ATC session's - let flightplan_id = flightplan["connection_id"] + let flightplan_id = flightplan["id"] userFlightplans[flightplan_id] = flightplan; + userFlightplans[flightplan_id]["not_filed"] = flightplan["connection_id"] === 0 // Long line again let flightplanElement = "
" + flightplan["callsign"] + "
"; $("#fox_flightplans").append(flightplanElement); } - showFlight(userFlightplans[result[0]["callsign"]]); + + $(".fox_button").click(function() { + if ($(this).hasClass("fox_active")) return; + + $(".fox_active").removeClass("fox_active"); + $(this).addClass("fox_active"); + + showFlight(userFlightplans[$(this).attr("id")]); + }); + + showFlight(result[0]); }); // Fetching airports information @@ -93,6 +120,7 @@ function showFlight(flight) { // Changing text in each class // FP before _ - means flightplan + $(".fp_is_filed").text(flight["not_filed"] ? "This flightplan was not filed" : ""); $(".fp_callsign").text(flight["callsign"]); $(".fp_depa_city").text(airports[flight["dep"]]["city"]); $(".fp_arra_city").text(airports[flight["arr"]]["city"]); @@ -117,30 +145,11 @@ function showSession(session) { if (!session) return; $(".atc_callsign").text(session["connection_id"]["callsign"]); - $(".atc_start_time").text(session["connection_id"]["start"]); - $(".atc_end_time").text(session["connection_id"]["end"]); + $(".atc_start_time").text(session["connection_id"]["start"].replace("T", " ")); + $(".atc_end_time").text(session["connection_id"]["end"].replace("T", " ")); $(".atc_trackedair").text(session["aircrafttracked"]); $(".atc_seenair").text(session["aircraftseen"]); $(".atc_squawks").text(session["squawksassigned"]); $(".atc_transfers").text(session["handoffsinitiated"]); $(".atc_received").text(session["handoffsreceived"]); } - -// Click event handler to left menu button -$(".fox_atc").click(function() { - if ($(this).hasClass("fox_atc_active")) return; - - $(".fox_atc_active").removeClass("fox_atc_active"); - $(this).addClass("fox_atc_active"); - - showSession(userSession[$(this).attr("id")]); -}) - -$(".fox_button").click(function() { - if ($(this).hasClass("fox_active")) return; - - $(".fox_active").removeClass("fox_active"); - $(this).addClass("fox_active"); - - showFlight(userFlightplans[$(this).attr("id")]); -}); diff --git a/templates/4O4.html b/src/templates/4O4.html similarity index 100% rename from templates/4O4.html rename to src/templates/4O4.html diff --git a/templates/include/template.html b/src/templates/include/template.html similarity index 100% rename from templates/include/template.html rename to src/templates/include/template.html diff --git a/templates/index.html b/src/templates/index.html similarity index 70% rename from templates/index.html rename to src/templates/index.html index c2dc018..5194eda 100644 --- a/templates/index.html +++ b/src/templates/index.html @@ -6,10 +6,10 @@

Enter your VATSIM CID

See your detailed profile statistic

-

+

@@ -34,12 +34,17 @@ {% block javascript_code %}