modified: app.py
This commit is contained in:
44
app.py
44
app.py
@@ -139,11 +139,11 @@ def fetch_and_cache_profile_picture(user_id, avatar_url):
|
|||||||
|
|
||||||
|
|
||||||
def get_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."""
|
"""Versucht, das Profilbild eines Benutzers aus Redis, lokalem Speicher und zuletzt durch Download zu holen."""
|
||||||
# Debug: Print avatar_url for each call
|
# Debugging: Überprüfen der empfangenen Werte
|
||||||
print(f"Fetching profile picture for user {user_id} with avatar_url: {avatar_url}")
|
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))
|
cached_image = r.get(str(user_id))
|
||||||
if cached_image:
|
if cached_image:
|
||||||
print(f"Redis cache hit for user {user_id}: {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")
|
local_image_path = os.path.join(PROFILE_IMAGE_DIR, f"{user_id}.png")
|
||||||
if os.path.exists(local_image_path):
|
if os.path.exists(local_image_path):
|
||||||
print(f"Local cache hit for user {user_id}")
|
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
|
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}")
|
print(f"Downloading profile picture for user {user_id}")
|
||||||
return fetch_and_cache_profile_picture(user_id, avatar_url)
|
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")
|
@app.route("/user_dashboard/<int:guild_id>/leaderboard")
|
||||||
def leaderboard(guild_id):
|
def leaderboard(guild_id):
|
||||||
"""Zeigt das Level- und XP-Leaderboard für die Benutzer eines Servers an."""
|
"""Zeigt das Level Leaderboard für einen bestimmten Server an."""
|
||||||
try:
|
if "discord_user" in session:
|
||||||
connection = get_db_connection()
|
connection = get_db_connection()
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
|
current_date = datetime.now()
|
||||||
|
one_month_ago = current_date - timedelta(days=30)
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT user_id, nickname, profile_picture, level, xp
|
SELECT nickname, profile_picture, level, xp, join_date
|
||||||
FROM user_data
|
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
|
ORDER BY level DESC, xp DESC
|
||||||
LIMIT 100
|
""", (guild_id, one_month_ago))
|
||||||
""", (guild_id,))
|
|
||||||
|
|
||||||
leaderboard_data = cursor.fetchall()
|
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()
|
cursor.close()
|
||||||
connection.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>")
|
@app.route("/server_giveaways/<int:guild_id>")
|
||||||
|
|||||||
Reference in New Issue
Block a user