modified: app.py
modified: templates/index.html
This commit is contained in:
29
app.py
29
app.py
@@ -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."""
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
<a href="{{ url_for('stop') }}"
|
||||
class="btn btn-danger btn-block {{ 'disabled' if not bot_running else '' }}">Stop Bot</a>
|
||||
<a href="{{ url_for('settings') }}" class="btn btn-secondary btn-block">Settings</a>
|
||||
<a href="{{ url_for('logs') }}" class="btn btn-secondary btn-block">Logs</a>
|
||||
<a href="{{ url_for('users') }}" class="btn btn-info btn-block">User Management</a>
|
||||
<a href="{{ url_for('logout') }}" class="btn btn-outline-secondary btn-block">Logout</a>
|
||||
<h5 class="card-title">Bot Statistics</h5>
|
||||
<p class="card-text">Total Messages Processed: {{ total_messages }}</p>
|
||||
<p class="card-text">Most Used Command: {{ most_used_command }}</p>
|
||||
</div>
|
||||
<h5 class="card-title">Bot Statistics</h5>
|
||||
<p class="card-text">Total Messages Processed: {{ total_messages }}</p>
|
||||
<p class="card-text">Most Used Command: {{ most_used_command }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user