modified: app.py

modified:   templates/index.html
This commit is contained in:
SimolZimol
2024-09-03 13:23:04 +02:00
parent b680b5af21
commit 71b3c3e8e5
2 changed files with 32 additions and 4 deletions

29
app.py
View File

@@ -74,7 +74,8 @@ def get_db_connection():
@app.route("/")
def index():
if "username" in session:
return render_template("index.html", bot_running=bot_status())
bot_stats = get_bot_statistics()
return render_template("index.html", bot_running=bot_status(), **bot_stats)
return redirect(url_for("login"))
@app.route("/login", methods=["GET", "POST"])
@@ -160,6 +161,32 @@ def get_logs():
return jsonify({"logs": "Log file not found."})
return redirect(url_for("login"))
def get_bot_statistics():
"""Berechnet grundlegende Statistiken für den Bot."""
connection = get_db_connection()
cursor = connection.cursor(dictionary=True)
# Beispielabfragen, anpassen je nach Datenbankstruktur
cursor.execute("SELECT COUNT(*) AS total_messages FROM chat_history")
total_messages = cursor.fetchone()["total_messages"]
cursor.execute("""
SELECT command_name, COUNT(*) AS usage_count
FROM command_log
GROUP BY command_name
ORDER BY usage_count DESC
LIMIT 1
""")
most_used_command = cursor.fetchone()["command_name"]
cursor.close()
connection.close()
return {
"total_messages": total_messages,
"most_used_command": most_used_command,
}
@app.route("/download_logs")
def download_logs():
"""Bietet die Log-Datei zum Download an."""