modified: app.py

This commit is contained in:
SimolZimol
2024-10-31 11:27:39 +01:00
parent e0e22c39e0
commit 171770b9ee

11
app.py
View File

@@ -97,11 +97,15 @@ def make_discord_session(token=None, state=None):
def fetch_and_cache_profile_picture(user_id, avatar_url):
"""Lädt das Profilbild herunter und speichert es lokal und in Redis."""
if not user_id or not avatar_url:
# Fallback auf ein Standardprofilbild, wenn keine gültigen Werte vorhanden sind
return "/static/default_profile.png"
local_image_path = os.path.join(PROFILE_IMAGE_DIR, f"{user_id}.png")
# Checken, ob das Bild schon lokal vorhanden ist
if os.path.exists(local_image_path):
r.set(user_id, local_image_path)
r.set(str(user_id), local_image_path) # Sicherstellen, dass der Key ein String ist
return local_image_path
try:
@@ -112,11 +116,12 @@ def fetch_and_cache_profile_picture(user_id, avatar_url):
img_file.write(response.content)
# Pfad in Redis speichern
r.set(user_id, local_image_path)
r.set(str(user_id), local_image_path) # Konvertiere user_id zu einem String
return local_image_path
except requests.RequestException as e:
print(f"Error fetching profile picture for user {user_id}: {e}")
return "/static/default_profile.png" # Standardbild
return "/static/default_profile.png" # Standardbild verwenden
def get_profile_picture(user_id, avatar_url):
"""Gibt den Pfad zum Profilbild eines Benutzers zurück, entweder aus Redis oder durch Abruf."""