From 4fd27bae1496fc7e6fb76746ffd82c626e537e02 Mon Sep 17 00:00:00 2001 From: Kierre Date: Fri, 7 Nov 2025 17:14:14 -0500 Subject: [PATCH] Format --- index.py | 90 ++++++++++++++++++++++++++++++++++++++----------------- ruff.toml | 7 +++++ 2 files changed, 70 insertions(+), 27 deletions(-) create mode 100644 ruff.toml diff --git a/index.py b/index.py index 2c5d473..6879167 100644 --- a/index.py +++ b/index.py @@ -5,63 +5,99 @@ import tomllib import logging import time -with open('config.toml', 'rb') as f: +with open("config.toml", "rb") as f: config = tomllib.load(f) -app = Flask('velping') +app = Flask("velping") logging.disable(logging.CRITICAL) uptime = {} + def ping(service): while True: - print(f'[I] Pinging {service}') + print(f"[I] Pinging {service}") try: - resp = requests.get(config['services'][service]) + resp = requests.get(config["services"][service]) resp.raise_for_status() - if uptime[service][config['frontend']['pings'] - 1] != 'I' and config['ntfy']['enabled']: - requests.post(f'https://{config['ntfy']['server']}/{config['ntfy']['topic']}', data=f'Service {service} is online') + if ( + uptime[service][config["frontend"]["pings"] - 1] != "I" + and config["ntfy"]["enabled"] + ): + requests.post( + f"https://{config['ntfy']['server']}/{config['ntfy']['topic']}", + data=f"Service {service} is online", + ) uptime[service].pop(0) - uptime[service].append('I') - print(f'[I] Pinging {service} worked!') + uptime[service].append("I") + print(f"[I] Pinging {service} worked!") except Exception as e: - if 'Remote end closed connection without response' in str(e) and config['pinging']['allow_empty_responses']: + if ( + "Remote end closed connection without response" in str(e) + and config["pinging"]["allow_empty_responses"] + ): uptime[service].pop(0) - uptime[service].append('I') - print(f'[I] Pinging {service} worked!') + uptime[service].append("I") + print(f"[I] Pinging {service} worked!") else: - if uptime[service][config['frontend']['pings'] - 1] != 'O' and config['ntfy']['enabled']: - requests.post(f'https://{config['ntfy']['server']}/{config['ntfy']['topic']}', data=f'Service {service} is offline') + if ( + uptime[service][config["frontend"]["pings"] - 1] != "O" + and config["ntfy"]["enabled"] + ): + requests.post( + f"https://{config['ntfy']['server']}/{config['ntfy']['topic']}", + data=f"Service {service} is offline", + ) uptime[service].pop(0) - uptime[service].append('O') - print(f'[E] An error happened while pinging for {service}: {e}') + uptime[service].append("O") + print(f"[E] An error happened while pinging for {service}: {e}") - time.sleep(config['pinging']['seconds_between_ping']) + time.sleep(config["pinging"]["seconds_between_ping"]) -for service in config['services']: + +for service in config["services"]: uptime[service] = [] - for ping_but_different in range(config['frontend']['pings']): - uptime[service].append('?') + for _ in range(config["frontend"]["pings"]): + uptime[service].append("?") + + threading.Thread( + target=ping, + args=(service,), + ).start() - threading.Thread(target=ping, args=(service,)).start() @app.errorhandler(404) def not_found(error): - return redirect('/', 303) + return redirect("/", 308) + @app.errorhandler(500) def internal_error(error): - return render_template('internal_error.xht', config=config), 500 + return render_template( + "internal_error.xht", + config=config, + ), 500 -@app.route('/style.css') + +@app.route("/style.css") def css(): - return send_file('assets/style.css') + return send_file("assets/style.css") -@app.route('/') + +@app.route("/") def root(): - return render_template('index.xht', config=config, services=config['services'], uptime=uptime), 200 + return render_template( + "index.xht", + config=config, + services=config["services"], + uptime=uptime, + ), 200 -app.run(port=config['frontend']['port'], host='::') + +app.run( + port=config["frontend"]["port"], + host="::", +) diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..6786bce --- /dev/null +++ b/ruff.toml @@ -0,0 +1,7 @@ +target-version = "py310" + +line-length = 88 + +[format] +indent-style = "tab" +docstring-code-format = false