From 3d8c4b0222a90f5b14ac24ced140c76fd4d9df15 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 11 Mar 2024 10:18:12 +0100 Subject: [PATCH] Continued: - fixed SQL string - partly reverted because simple code like 'tuple(row)' doesn't work --- daemon.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/daemon.py b/daemon.py index 1dcb739..e50d52b 100755 --- a/daemon.py +++ b/daemon.py @@ -56,10 +56,17 @@ templates = Jinja2Templates(directory="templates") @router.get(config.get("base_url") + "/api/info.json", response_class=JSONResponse) def api_info(): - database.cursor.execute("SELECT (SELECT COUNT(domain) AS total_websites FROM instances), (SELECT COUNT(domain) AS supported_instances FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey', 'peertube', 'takahe', 'gotosocial', 'brighteon', 'wildebeest', 'bookwyrm', 'mitra', 'areionskey', 'mammuthus', 'neodb', 'smithereen', 'vebinet')), (SELECT COUNT(blocker) FROM blocks) AS total_blocks, (SELECT COUNT(domain) AS erroneous_instances FROM instances WHERE last_error_details IS NOT NULL)") + database.cursor.execute("SELECT (SELECT COUNT(domain) FROM instances) AS total_websites, (SELECT COUNT(domain) FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey', 'peertube', 'takahe', 'gotosocial', 'brighteon', 'wildebeest', 'bookwyrm', 'mitra', 'areionskey', 'mammuthus', 'neodb', 'smithereen', 'vebinet')) AS supported_instances, (SELECT COUNT(blocker) FROM blocks) AS total_blocks, (SELECT COUNT(domain) FROM instances WHERE last_error_details IS NOT NULL) AS erroneous_instances") + row = database.cursor.fetchone() - return JSONResponse(status_code=200, content=tuple(row)) + return JSONResponse(status_code=200, content={ + "total_websites" : row["total_websites"], + "supported_instances": row["supported_instances"], + "total_blocks" : row["total_blocks"], + "erroneous_instances": row["erroneous_instances"], + }) + @router.get(config.get("base_url") + "/api/scoreboard.json", response_class=JSONResponse) def api_scoreboard(mode: str, amount: int): -- 2.39.5