modified: app.py
This commit is contained in:
34
app.py
34
app.py
@@ -140,6 +140,9 @@ def fetch_and_cache_profile_picture(user_id, avatar_url):
|
||||
|
||||
def get_profile_picture(user_id, avatar_url):
|
||||
"""Gibt den Pfad zum Profilbild eines Benutzers zurück, zuerst aus Redis, dann aus dem lokalen Speicher und zuletzt durch Download."""
|
||||
# Debug: Print avatar_url for each call
|
||||
print(f"Fetching profile picture for user {user_id} with avatar_url: {avatar_url}")
|
||||
|
||||
# 1. Prüfen, ob das Bild in Redis gecached ist
|
||||
cached_image = r.get(str(user_id))
|
||||
if cached_image:
|
||||
@@ -153,10 +156,11 @@ def get_profile_picture(user_id, avatar_url):
|
||||
r.set(str(user_id), local_image_path) # Speichern in Redis
|
||||
return local_image_path
|
||||
|
||||
# 3. Wenn das Bild weder in Redis noch lokal ist, herunterladen und speichern
|
||||
# 3. Download und Cache des Bilds
|
||||
print(f"Downloading profile picture for user {user_id}")
|
||||
return fetch_and_cache_profile_picture(user_id, avatar_url)
|
||||
|
||||
|
||||
@app.context_processor
|
||||
def utility_processor():
|
||||
def get_profile_picture(user_id, avatar_url):
|
||||
@@ -586,31 +590,33 @@ def user_dashboard(guild_id):
|
||||
|
||||
@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:
|
||||
"""Zeigt das Level- und XP-Leaderboard für die Benutzer eines Servers an."""
|
||||
try:
|
||||
connection = get_db_connection()
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
current_date = datetime.now()
|
||||
one_month_ago = current_date - timedelta(days=30)
|
||||
|
||||
cursor.execute("""
|
||||
SELECT nickname, profile_picture, level, xp, join_date
|
||||
SELECT user_id, nickname, profile_picture, level, xp
|
||||
FROM user_data
|
||||
WHERE guild_id = %s
|
||||
AND ban = 0
|
||||
AND (leave_date IS NULL OR leave_date > %s)
|
||||
WHERE guild_id = %s AND (ban = 0) AND (leave_date IS NULL OR leave_date > NOW() - INTERVAL 1 MONTH)
|
||||
ORDER BY level DESC, xp DESC
|
||||
""", (guild_id, one_month_ago))
|
||||
LIMIT 100
|
||||
""", (guild_id,))
|
||||
|
||||
leaderboard_data = cursor.fetchall()
|
||||
|
||||
# Debug: Print profile_picture URLs for all users in the leaderboard
|
||||
for user in leaderboard_data:
|
||||
print(f"User ID: {user['user_id']}, Profile Picture: {user['profile_picture']}")
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
# Übergabe von enumerate an das Template
|
||||
return render_template("leaderboard.html", leaderboard=leaderboard_data, guild_id=guild_id, enumerate=enumerate)
|
||||
return redirect(url_for("landing_page"))
|
||||
return render_template("leaderboard.html", leaderboard=leaderboard_data, guild_id=guild_id)
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Database error: {e}")
|
||||
return "Database error", 500
|
||||
|
||||
|
||||
|
||||
@app.route("/server_giveaways/<int:guild_id>")
|
||||
|
||||
Reference in New Issue
Block a user