mirror of
https://github.com/uw935/vatsimfox.git
synced 2026-09-17 04:48:58 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acf1691fd0 | ||
|
|
7cf015be22 | ||
|
|
b22879474b | ||
|
|
f7f76b1cfd | ||
|
|
1cc1772c4b | ||
|
|
b4d0c388ef | ||
|
|
f4230e1bf7 | ||
|
|
9ba02586ad | ||
|
|
4a627cc8b0 | ||
|
|
ea704ca5af | ||
|
|
4ef47c6ce5 | ||
|
|
f860de470f | ||
|
|
2d1e4e6f9f |
+34
-14
@@ -1,23 +1,43 @@
|
||||
name: deployment on server
|
||||
name: Create and publish a Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build-and-push-image:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
- name: update bot
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
username: ${{ secrets.SERVER_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
port: 22
|
||||
script: |
|
||||
cd /home/deploy/vatsimfox && git pull origin master --force && cd /home/deploy/vatsimfox/src
|
||||
docker compose up -d --build
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
||||
with:
|
||||
context: src/.
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
+1
-1
@@ -9,4 +9,4 @@ RUN pip install -r requirements.txt
|
||||
|
||||
COPY . /build/
|
||||
|
||||
CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"]
|
||||
CMD ["python3", "app.py"]
|
||||
+100
-25
@@ -1,41 +1,116 @@
|
||||
import uvicorn
|
||||
import requests
|
||||
from flask import Flask, render_template, abort, request, jsonify
|
||||
|
||||
from fastapi import (
|
||||
FastAPI,
|
||||
Request,
|
||||
HTTPException,
|
||||
)
|
||||
from fastapi.responses import FileResponse
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
VATSIM_API_URL = "https://api.vatsim.net/v2/"
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index_page():
|
||||
return render_template("index.html")
|
||||
app = FastAPI(
|
||||
title="VATSIM Fox",
|
||||
docs_url=None,
|
||||
redoc_url=None,
|
||||
openapi_url=None,
|
||||
redirect_slashes=True
|
||||
)
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def errorhandler_page(_):
|
||||
return render_template("4O4.html"), 404
|
||||
@app.get("/")
|
||||
async def get_index_page(request: Request):
|
||||
"""
|
||||
Index page
|
||||
|
||||
:param request: FastAPI request
|
||||
:return: HTML template
|
||||
"""
|
||||
|
||||
return templates.TemplateResponse(
|
||||
name="index.html",
|
||||
context={
|
||||
"request": request,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.route("/api/request")
|
||||
def request_handler():
|
||||
if request_string := request.args.get("request_string"):
|
||||
@app.get("/favicon.ico", include_in_schema=False)
|
||||
async def get_favicon():
|
||||
"""
|
||||
Get favicon
|
||||
|
||||
:return: Icon file
|
||||
"""
|
||||
|
||||
return FileResponse("./static/icon.ico")
|
||||
|
||||
|
||||
@app.get("/{cid}/")
|
||||
async def get_viewer_page(request: Request, cid: str = None):
|
||||
"""
|
||||
Viewer page
|
||||
|
||||
:param request: FastAPI request
|
||||
:param cid: User CID
|
||||
:return: HTML template
|
||||
"""
|
||||
try:
|
||||
user = requests.get(f"{VATSIM_API_URL}members/{cid}").json()
|
||||
except requests.exceptions.JSONDecodeError:
|
||||
raise HTTPException(404)
|
||||
|
||||
if "detail" in user and user["detail"] == "Not Found":
|
||||
raise HTTPException(404)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
name="viewer.html",
|
||||
context={
|
||||
"user": user,
|
||||
"request": request,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.exception_handler(404)
|
||||
async def error_handler(request: Request, _):
|
||||
"""
|
||||
Handler to the 404 HTTP error
|
||||
|
||||
:param request: FastAPI request
|
||||
:return: HTML template
|
||||
"""
|
||||
|
||||
return templates.TemplateResponse(
|
||||
name="4O4.html",
|
||||
context={
|
||||
"request": request,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.get("/api/request")
|
||||
def request_handler(request_string: str):
|
||||
"""
|
||||
Wrapper to the VATSIM API functions
|
||||
|
||||
:param request_string: String that will fetched from VATSIM API
|
||||
"""
|
||||
|
||||
if request_string:
|
||||
try:
|
||||
return requests.get(f"{VATSIM_API_URL}{request_string}").json()
|
||||
except requests.exceptions.JSONDecodeError:
|
||||
return jsonify({"result": "error", "message": "Something went wrong. Report that error please"})
|
||||
return {"result": "error", "message": "Something went wrong. Report that error please"}
|
||||
|
||||
return jsonify({"result": "not found", "message": "Not found"})
|
||||
|
||||
|
||||
@app.route("/<int:cid>/")
|
||||
def viewer_page(cid):
|
||||
user = requests.get(f"{VATSIM_API_URL}members/{cid}").json()
|
||||
|
||||
if "detail" in user and user["detail"] == "Not Found":
|
||||
return abort(404)
|
||||
|
||||
return render_template("viewer.html", user=user)
|
||||
return {"result": "not found", "message": "Not found"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=80)
|
||||
uvicorn.run(app=app, host="0.0.0.0", port=80)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Flask==2.2.5
|
||||
fastapi==0.110.2
|
||||
requests==2.31.0
|
||||
uvicorn==0.29.0
|
||||
flake8==5.0.4
|
||||
Jinja2==3.1.3
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
<meta content="yes" name="apple-touch-fullscreen" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="#FA8232">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="viewport" content="width = 320, initial-scale = 2.3, user-scalable = no">
|
||||
<link rel="icon" href="{{ url_for('static', filename='icon.ico') }}" type="image/x-icon">
|
||||
<link rel="icon" href="{{ url_for('static', path='icon.ico') }}" type="image/x-icon">
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
|
||||
@@ -36,19 +35,24 @@
|
||||
</style>
|
||||
<body>
|
||||
<main>
|
||||
<div class="container py-4">
|
||||
<header class="pb-3 mb-4 border-bottom">
|
||||
<header class="border-bottom">
|
||||
<div class="container py-4">
|
||||
<a href="/" class="d-flex align-items-center text-dark text-decoration-none">
|
||||
<span class="fs-4">🦊 VATSIM <span class="text-primary">Fox</span></span>
|
||||
<span class="fs-4">🦊 VATSIM <span class="text-primary">Fox</span></span>
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="container py-4">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
<footer class="pt-3 mt-4 text-muted border-top">
|
||||
created by <a href="https://uw935.t.me/" style="text-decoration: underline; cursor: pointer;">uw935</a> (1606255)
|
||||
</footer>
|
||||
</div>
|
||||
<footer class="text-muted border-top">
|
||||
<div class="container py-4">
|
||||
created by
|
||||
<a href="https://uw935.com/" style="text-decoration: underline; cursor: pointer;">uw935</a> (1606255)
|
||||
</div>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
|
||||
|
||||
+26
-24
@@ -2,33 +2,35 @@
|
||||
{% block title %}VATSIM Fox — view detailed profile statistic{% endblock %}
|
||||
{% block content %}
|
||||
<div class="p-5 mb-4 bg-light rounded-3">
|
||||
<div class="container-fluid py-5">
|
||||
<h1 class="display-5 fw-bold">Enter your VATSIM CID</h1>
|
||||
<p class="col-md-8 fs-4">See your detailed profile statistic</p>
|
||||
<div class="d-flex" role="search">
|
||||
<input class="fox_input form-control me-2" type="number" placeholder="100000" aria-label="CID">
|
||||
<button class="fox_submit btn btn-outline-primary" type="submit">Search</button>
|
||||
</div>
|
||||
<p class="fox_message text-primary col-md-8 fs-4"></p>
|
||||
</div>
|
||||
<div class="container-fluid py-5">
|
||||
<h1 class="display-5 fw-bold">Enter your VATSIM CID</h1>
|
||||
<p class="col-md-8 fs-4">See your detailed profile statistic</p>
|
||||
<div class="d-flex" role="search">
|
||||
<input class="fox_input form-control me-2" type="number" placeholder="100000" aria-label="CID">
|
||||
<button class="fox_submit btn btn-outline-primary" type="submit">Search</button>
|
||||
</div>
|
||||
<p class="fox_message text-primary col-md-8 fs-4"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4 row align-items-md-stretch">
|
||||
<div class="col-md-6">
|
||||
<div class="h-100 p-5 text-bg-dark rounded-3">
|
||||
<h2>About</h2>
|
||||
<p>VATSIM Fox is an open-source project to make it easier for users to see their detailed profile statistic</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="h-100 p-5 bg-light border rounded-3">
|
||||
<h2>Open source project</h2>
|
||||
<p>This project is fully opened, so you can contribute in it if you want</p>
|
||||
<a href="https://github.com/uw935/vatsimfox">
|
||||
<button class="btn btn-outline-secondary" type="button">GitHub</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="h-100 p-5 text-bg-dark rounded-3">
|
||||
<h2>About</h2>
|
||||
<p>VATSIM Fox is an open-source project to make it easier for users to see their detailed profile statistic</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="h-100 p-5 bg-light border rounded-3">
|
||||
<h2>Open source project</h2>
|
||||
<p>This project is fully opened, so you can contribute in it if you want</p>
|
||||
|
||||
<a href="https://github.com/uw935/vatsimfox">
|
||||
<button class="btn btn-outline-secondary" type="button">GitHub</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block javascript_code %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "/include/template.html" %}
|
||||
{% block title %}User {{user["id"]}} statistic — VATSIM Fox{% endblock %}
|
||||
{% block header_css %}
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='viewer.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', path='viewer.css') }}">
|
||||
<link href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" rel="stylesheet"/>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
@@ -146,5 +146,5 @@
|
||||
|
||||
$(".date_registration").text("{{user['reg_date']}}".replace("T", " "));
|
||||
</script>
|
||||
<script type="text/javascript" src="{{ url_for('static', filename='viewer.js') }}"></script>
|
||||
<script type="text/javascript" src="{{ url_for('static', path='viewer.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user