From 37fde20fa1e2ac3f114388799d199aeb783bad20 Mon Sep 17 00:00:00 2001 From: Blue Fox Date: Thu, 29 Dec 2022 09:02:15 +0100 Subject: [PATCH] First commit --- .gitignore | 9 +++++++++ SETTINGS.py | 3 +++ main.py | 21 +++++++++++++++++++++ routes.py | 9 +++++++++ static/index.css | 10 ++++++++++ templates/index.html | 13 +++++++++++++ 6 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 SETTINGS.py create mode 100644 main.py create mode 100644 routes.py create mode 100644 static/index.css create mode 100644 templates/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f724bc9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# all virtual env files +venv + + +# IDE files +.idea + +# python3 cache files +__pycache__ diff --git a/SETTINGS.py b/SETTINGS.py new file mode 100644 index 0000000..f306138 --- /dev/null +++ b/SETTINGS.py @@ -0,0 +1,3 @@ +FLASK_NAME = "DWDeathermap" +HTTP_PORT = 8080 +HTTP_HOST = "0.0.0.0" \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..7b9d79c --- /dev/null +++ b/main.py @@ -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("/") # 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 "

404 Not found!

", 404 # if nothing matches return 404 Not Found + +if __name__ == "__main__": + app.run(SETTINGS.HTTP_HOST, SETTINGS.HTTP_PORT) \ No newline at end of file diff --git a/routes.py b/routes.py new file mode 100644 index 0000000..5b69f5b --- /dev/null +++ b/routes.py @@ -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} diff --git a/static/index.css b/static/index.css new file mode 100644 index 0000000..0b053a2 --- /dev/null +++ b/static/index.css @@ -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 } \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..016ec39 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,13 @@ + + + + + {{ flask_name }} + + + +

A lot TO-DO!

+
+

Just a first demo!

+ + \ No newline at end of file