modified: app.py
new file: templates/leaderboard.html
This commit is contained in:
30
app.py
30
app.py
@@ -8,7 +8,7 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import psutil
|
import psutil
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from flask_session import Session
|
from flask_session import Session
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@@ -488,6 +488,34 @@ def user_dashboard(guild_id):
|
|||||||
flash("Please log in to view your dashboard.", "danger")
|
flash("Please log in to view your dashboard.", "danger")
|
||||||
return redirect(url_for("landing_page"))
|
return redirect(url_for("landing_page"))
|
||||||
|
|
||||||
|
@app.route("/user_dashboard/<int:guild_id>/leaderboard")
|
||||||
|
def leaderboard(guild_id):
|
||||||
|
"""Zeigt das Level Leaderboard für einen bestimmten Server an."""
|
||||||
|
if "discord_user" in session:
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
|
# Holen des aktuellen Datums und des Datums von einem Monat zurück
|
||||||
|
current_date = datetime.now()
|
||||||
|
one_month_ago = current_date - timedelta(days=30)
|
||||||
|
|
||||||
|
# Abfrage für das Leaderboard
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT nickname, profile_picture, level, xp, join_date
|
||||||
|
FROM user_data
|
||||||
|
WHERE guild_id = %s
|
||||||
|
AND ban = 0
|
||||||
|
AND (leave_date IS NULL OR leave_date > %s)
|
||||||
|
ORDER BY level DESC, xp DESC
|
||||||
|
""", (guild_id, one_month_ago))
|
||||||
|
|
||||||
|
leaderboard_data = cursor.fetchall()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
return render_template("leaderboard.html", leaderboard=leaderboard_data, guild_id=guild_id)
|
||||||
|
return redirect(url_for("landing_page"))
|
||||||
|
|
||||||
@app.route("/server_giveaways/<int:guild_id>")
|
@app.route("/server_giveaways/<int:guild_id>")
|
||||||
def server_giveaways(guild_id):
|
def server_giveaways(guild_id):
|
||||||
|
|||||||
57
templates/leaderboard.html
Normal file
57
templates/leaderboard.html
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Level Leaderboard</title>
|
||||||
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
.profile-picture {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 50%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
.table-container {
|
||||||
|
max-height: 600px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% include 'navigation.html' %}
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h2 class="text-center">Level Leaderboard - Server {{ guild_id }}</h2>
|
||||||
|
<div class="table-container mt-4">
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Rank</th>
|
||||||
|
<th>Profile</th>
|
||||||
|
<th>Nickname</th>
|
||||||
|
<th>Level</th>
|
||||||
|
<th>XP</th>
|
||||||
|
<th>Joined</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for index, user in enumerate(leaderboard, start=1) %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ index }}</td>
|
||||||
|
<td><img src="{{ user.profile_picture }}" alt="Profile Picture" class="profile-picture"></td>
|
||||||
|
<td>{{ user.nickname }}</td>
|
||||||
|
<td>{{ user.level }}</td>
|
||||||
|
<td>{{ user.xp }}</td>
|
||||||
|
<td>{{ user.join_date }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% if leaderboard|length == 0 %}
|
||||||
|
<p class="text-center text-muted">No users found for this leaderboard.</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<a href="{{ url_for('user_dashboard', guild_id=guild_id) }}" class="btn btn-secondary mt-3">Back to Dashboard</a>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user