From 4d2fe89cd59a8b84202413567b1f51ffc9508ce4 Mon Sep 17 00:00:00 2001 From: ahoemann Date: Thu, 12 Dec 2024 08:11:13 +0100 Subject: [PATCH] add: config-parser; fix: offline status internal server error --- adrianux.toml | 5 +++++ app.py | 31 ++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 adrianux.toml diff --git a/adrianux.toml b/adrianux.toml new file mode 100644 index 0000000..3aeca5a --- /dev/null +++ b/adrianux.toml @@ -0,0 +1,5 @@ +[site] +git_url="http://localhost:5000" +website_url="http://localhost:8080" +[mode] +debug_mode=True diff --git a/app.py b/app.py index 3aa37fb..10e479d 100755 --- a/app.py +++ b/app.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 from flask import Flask, render_template, redirect, url_for import requests +import configparser + app = Flask(__name__) @@ -18,22 +20,29 @@ def homepage(): @app.route("/monitoring") def monitoring(): - git_status = get_status("https://git.adrianux.net") - website_status = get_status("https://adrianux.net") - return render_template("monitoring.html", git_status = git_status, website_status = website_status ) + 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): - match get_status_code(link): - case 200: - return "ONLINE" - case 500: - return "ERROR" - case _: - return "OFFLINE" + 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__": - app.run(debug=False) + mode = parser("mode","debug_mode") + app.run(debug=mode)