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("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
if "username" in session:
|
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"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
@app.route("/login", methods=["GET", "POST"])
|
@app.route("/login", methods=["GET", "POST"])
|
||||||
@@ -160,6 +161,32 @@ def get_logs():
|
|||||||
return jsonify({"logs": "Log file not found."})
|
return jsonify({"logs": "Log file not found."})
|
||||||
return redirect(url_for("login"))
|
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")
|
@app.route("/download_logs")
|
||||||
def download_logs():
|
def download_logs():
|
||||||
"""Bietet die Log-Datei zum Download an."""
|
"""Bietet die Log-Datei zum Download an."""
|
||||||
|
|||||||
@@ -24,14 +24,15 @@
|
|||||||
<a href="{{ url_for('stop') }}"
|
<a href="{{ url_for('stop') }}"
|
||||||
class="btn btn-danger btn-block {{ 'disabled' if not bot_running else '' }}">Stop Bot</a>
|
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('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('users') }}" class="btn btn-info btn-block">User Management</a>
|
||||||
<a href="{{ url_for('logout') }}" class="btn btn-outline-secondary btn-block">Logout</a>
|
<a href="{{ url_for('logout') }}" class="btn btn-outline-secondary btn-block">Logout</a>
|
||||||
|
</div>
|
||||||
<h5 class="card-title">Bot Statistics</h5>
|
<h5 class="card-title">Bot Statistics</h5>
|
||||||
<p class="card-text">Total Messages Processed: {{ total_messages }}</p>
|
<p class="card-text">Total Messages Processed: {{ total_messages }}</p>
|
||||||
<p class="card-text">Most Used Command: {{ most_used_command }}</p>
|
<p class="card-text">Most Used Command: {{ most_used_command }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user