First commit

This commit is contained in:
Blue Fox 2022-12-29 09:02:15 +01:00
commit 37fde20fa1
6 changed files with 65 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
# all virtual env files
venv
# IDE files
.idea
# python3 cache files
__pycache__

3
SETTINGS.py Normal file
View File

@ -0,0 +1,3 @@
FLASK_NAME = "DWDeathermap"
HTTP_PORT = 8080
HTTP_HOST = "0.0.0.0"

21
main.py Normal file
View File

@ -0,0 +1,21 @@
from flask import Flask
import SETTINGS
import routes
import re
app = Flask(SETTINGS.FLASK_NAME)
@app.route('/', defaults={'route': '/'}) # catch HTTP / and set route to ""
@app.route("/<path:route>") # catch everything else and set route to the path
def route(route: str):
if not route.endswith("/"):
route += "/"
for r in routes.ROUTES:
if match := re.match(r, route):
return routes.ROUTES[r](match) # call the handler for the function
return "<html><head></head><body><h1>404 Not found!</h1></body></html>", 404 # if nothing matches return 404 Not Found
if __name__ == "__main__":
app.run(SETTINGS.HTTP_HOST, SETTINGS.HTTP_PORT)

9
routes.py Normal file
View File

@ -0,0 +1,9 @@
import re
from flask import render_template
import SETTINGS
def web_root(match: re.Match):
print(match.string)
return render_template("index.html", flask_name=SETTINGS.FLASK_NAME)
ROUTES = {r"^/$": web_root, r"^([A-Za-z0-9/]*)$": web_root}

10
static/index.css Normal file
View File

@ -0,0 +1,10 @@
body {
padding-top: 3em;
background-color: #333333;
color: #ffffff;
text-align: center;
font-size: 15pt;
}
p { font-family: Ubuntu; }
hr { width: 12%; color: #ff1122; margin-bottom: 1em }

13
templates/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ flask_name }}</title>
<link rel="stylesheet" href="/static/index.css">
</head>
<body>
<h1>A lot TO-DO!</h1>
<hr>
<p>Just a first demo!</p>
</body>
</html>