modified: app.py
This commit is contained in:
10
app.py
10
app.py
@@ -8,6 +8,7 @@ import spotipy
|
|||||||
from spotipy.oauth2 import SpotifyOAuth
|
from spotipy.oauth2 import SpotifyOAuth
|
||||||
import random
|
import random
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
|
import re
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = os.getenv("SECRET_KEY")
|
app.secret_key = os.getenv("SECRET_KEY")
|
||||||
@@ -27,6 +28,10 @@ def get_spotify_client():
|
|||||||
def similarity(a, b):
|
def similarity(a, b):
|
||||||
return SequenceMatcher(None, a.lower(), b.lower()).ratio()
|
return SequenceMatcher(None, a.lower(), b.lower()).ratio()
|
||||||
|
|
||||||
|
def clean_title(title):
|
||||||
|
# Entfernt (feat. ...), [Remix ...], (Remix), [xyz], usw.
|
||||||
|
return re.sub(r"(\s*[\(\[][^)\]]*[\)\]])", "", title).strip()
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
return render_template("login.html")
|
return render_template("login.html")
|
||||||
@@ -154,6 +159,11 @@ def check_answer():
|
|||||||
correct_answer = data.get('correct_answer', '').lower()
|
correct_answer = data.get('correct_answer', '').lower()
|
||||||
game_mode = data.get('game_mode', 'artist')
|
game_mode = data.get('game_mode', 'artist')
|
||||||
|
|
||||||
|
# Titel ggf. bereinigen
|
||||||
|
if game_mode == 'title':
|
||||||
|
guess = clean_title(guess)
|
||||||
|
correct_answer = clean_title(correct_answer)
|
||||||
|
|
||||||
# Bei Jahr-Modus: Exakte Übereinstimmung prüfen
|
# Bei Jahr-Modus: Exakte Übereinstimmung prüfen
|
||||||
if game_mode == 'year':
|
if game_mode == 'year':
|
||||||
is_correct = guess == correct_answer
|
is_correct = guess == correct_answer
|
||||||
|
|||||||
Reference in New Issue
Block a user