Adrianux.net/app.py
ahoemann 4d2fe89cd5
All checks were successful
/ update (push) Successful in 0s
add: config-parser; fix: offline status internal server error
2024-12-12 08:11:13 +01:00

48 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
from flask import Flask, render_template, redirect, url_for
import requests
import configparser
app = Flask(__name__)
@app.route("/imprint")
def root():
return render_template("imprint.html")
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/")
def homepage():
return render_template("homepage.html")
@app.route("/monitoring")
def monitoring():
git_url = parser("site", "git_url")
website_url = parser("site", "website_url")
return render_template("monitoring.html", git_status = get_status(git_url), website_status = get_status(website_url) )
def get_status_code(link):
requested_site = requests.get(link)
return requested_site.status_code
def get_status(link):
try:
match get_status_code(link):
case 200:
return "ONLINE"
case _:
return "ERROR"
except:
return "OFFLINE"
def parser(section, attribute):
config = configparser.RawConfigParser()
config.read("./adrianux.toml")
return config.get(section, attribute)
if __name__ == "__main__":
mode = parser("mode","debug_mode")
app.run(debug=mode)