modified: app.py

This commit is contained in:
SimolZimol
2025-06-01 18:51:12 +02:00
parent 860d36aaf8
commit 9b8b92f231

15
app.py
View File

@@ -10,6 +10,7 @@ import random
from difflib import SequenceMatcher
import re
import json
import unicodedata
app = Flask(__name__)
app.secret_key = os.getenv("SECRET_KEY")
@@ -53,13 +54,20 @@ def similarity(a, b):
return SequenceMatcher(None, a.lower(), b.lower()).ratio()
def clean_title(title):
# Unicode-Normalisierung (z.B. é -> e)
title = unicodedata.normalize('NFKD', title)
title = "".join([c for c in title if not unicodedata.combining(c)])
# Entfernt alles in () oder []
title = re.sub(r"(\s*[\(\[][^)\]]*[\)\]])", "", title)
# Vereinheitliche Apostrophen und Anführungszeichen
title = title.replace("", "'").replace("", "'").replace("`", "'")
title = title.replace('"', '').replace("", '').replace("", '').replace("", '')
title = title.replace("'", "") # Optional: alle Apostrophen entfernen
return title.strip()
title = title.replace("'", "")
# Entferne alle nicht-alphanumerischen Zeichen (außer Leerzeichen)
title = re.sub(r"[^a-zA-Z0-9äöüÄÖÜß ]", "", title)
# Mehrfache Leerzeichen zu einem
title = re.sub(r"\s+", " ", title)
return title.strip().lower()
def get_all_playlist_tracks(sp, playlist_id):
tracks = []
@@ -215,7 +223,8 @@ def check_answer():
game_mode = data.get('game_mode', 'artist')
playlist_id = data.get('playlist_id')
if game_mode == 'title':
# Immer clean_title für title und artist
if game_mode in ['title', 'artist']:
guess = clean_title(guess)
correct_answer = clean_title(correct_answer)