modified: app.py

This commit is contained in:
SimolZimol
2024-10-31 19:42:31 +01:00
parent 5f3e207eba
commit 32206540e8

44
app.py
View File

@@ -139,11 +139,11 @@ 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}")
"""Versucht, das Profilbild eines Benutzers aus Redis, lokalem Speicher und zuletzt durch Download zu holen."""
# Debugging: Überprüfen der empfangenen Werte
print(f"Checking profile picture for user {user_id} with avatar URL: {avatar_url}")
# 1. Prüfen, ob das Bild in Redis gecached ist
# 1. Prüfen, ob das Bild in Redis gespeichert ist
cached_image = r.get(str(user_id))
if cached_image:
print(f"Redis cache hit for user {user_id}: {cached_image}")
@@ -153,10 +153,10 @@ def get_profile_picture(user_id, avatar_url):
local_image_path = os.path.join(PROFILE_IMAGE_DIR, f"{user_id}.png")
if os.path.exists(local_image_path):
print(f"Local cache hit for user {user_id}")
r.set(str(user_id), local_image_path) # Speichern in Redis
r.set(str(user_id), local_image_path) # Cache das Bild in Redis
return local_image_path
# 3. Download und Cache des Bilds
# 3. Wenn das Bild weder in Redis noch lokal ist, herunterladen und speichern
print(f"Downloading profile picture for user {user_id}")
return fetch_and_cache_profile_picture(user_id, avatar_url)
@@ -590,33 +590,31 @@ def user_dashboard(guild_id):
@app.route("/user_dashboard/<int:guild_id>/leaderboard")
def leaderboard(guild_id):
"""Zeigt das Level- und XP-Leaderboard für die Benutzer eines Servers an."""
try:
"""Zeigt das Level Leaderboard für einen bestimmten Server an."""
if "discord_user" in session:
connection = get_db_connection()
cursor = connection.cursor(dictionary=True)
current_date = datetime.now()
one_month_ago = current_date - timedelta(days=30)
cursor.execute("""
SELECT user_id, nickname, profile_picture, level, xp
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 > NOW() - INTERVAL 1 MONTH)
WHERE guild_id = %s
AND ban = 0
AND (leave_date IS NULL OR leave_date > %s)
ORDER BY level DESC, xp DESC
LIMIT 100
""", (guild_id,))
""", (guild_id, one_month_ago))
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()
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
# Ü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"))
@app.route("/server_giveaways/<int:guild_id>")