diff --git a/quiz/.env b/quiz/.env index f58c968..163fed7 100644 --- a/quiz/.env +++ b/quiz/.env @@ -1,3 +1,6 @@ FLASK_APP=quiz.py -FLASK_ENV=development +#FLASK_ENV=development +FLASK_DEBUG=True +FLASK_RUN_HOST=0.0.0.0 +#FLASK_RUN_HOST=127.0.0.1 FLASK_RUN_PORT=5003 diff --git a/quiz/quiz.html b/quiz/quiz.html deleted file mode 100644 index b785fbf..0000000 --- a/quiz/quiz.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - Quiz - - -
- {% for question in q_a %} -

{{ question.question }}

- -

{{ question.answer }}

- {% endfor %} - -
- - diff --git a/quiz/quiz.py b/quiz/quiz.py index 8e3e244..f30273a 100644 --- a/quiz/quiz.py +++ b/quiz/quiz.py @@ -1,11 +1,9 @@ import os -from flask import Flask, render_template -from dotenv import load_dotenv +from flask import Flask, redirect, render_template, request, session import csv # CSV handling import random - -load_dotenv() # Laden Sie die Umgebungsvariablen aus der .env-Datei +app = Flask(__name__) def load_database(): file = os.path.join(os.path.expanduser("~"), "Austausch", "fragen1.csv") @@ -22,18 +20,47 @@ def load_database(): answer = str(row[2]) # Antwort (3. Spalte in der CSV Datenbank) q_a.append({"index": index,"question": question, "answer": answer}) # Eine Liste bauen -app = Flask(__name__) + return q_a + +fragen_liste = load_database() +random.shuffle(fragen_liste) + +current_index = 0 +last_correct = None + +debugtxt="" @app.route('/') -#def home(): -# return 'Willkommen beim Quiz!' -# -def quiz(): - # Hier können Sie den HTML-Code für Ihr Quiz-Formular rendern - return render_template('quiz.html') -if __name__ == '__main__': -# app.run(debug=True) - load_database() - port = int(os.getenv("FLASK_RUN_PORT", 5000)) - app.run(debug=True,host="0.0.0.0", port=port) +def quiz(): + + return render_template('quiz.html', frage=fragen_liste[current_index],last_correct=last_correct,debugtxt=debugtxt) + +@app.route('/submit_quiz', methods=['POST']) +def submit_quiz(): + global current_index + global fragen_liste + global debugtxt + + # Überprüfen Sie die Antwort und aktualisieren Sie current_index + user_answer = request.form.get('answer') + correct_answer = fragen_liste[current_index]['answer'] + + if user_answer == correct_answer: + last_correct = True + debugtxt = correct_answer + " ist richtig! passt zu deiner Angabe: " + user_answer + else: + last_correct = False +# debugtxt += "\n" +# debugtxt += "\n" + debugtxt = "falsch: Richtig wäre " +correct_answer + " / und nicht: " + user_answer + current_index += 1 + + # Überprüfen, ob wir alle Fragen beantwortet haben + if current_index >= len(fragen_liste): + fragen_liste = load_database() + random.shuffle(fragen_liste) + current_index=0 + + # Leiten Sie den Benutzer zur nächsten Frage weiter + return redirect('/') diff --git a/quiz/templates/choose.html b/quiz/templates/choose.html new file mode 100644 index 0000000..8642356 --- /dev/null +++ b/quiz/templates/choose.html @@ -0,0 +1,165 @@ + + + + + + + + Login + + + + + +
+

Wähle eine Kategorie:

+ +
+ + + \ No newline at end of file diff --git a/quiz/templates/eval.html b/quiz/templates/eval.html new file mode 100644 index 0000000..a309121 --- /dev/null +++ b/quiz/templates/eval.html @@ -0,0 +1,119 @@ + + + + + + + + {{htmltitle}} + + + + + +
+

Richtig!
Dein BonBon ist unterwegs

+

N/A von N/A beantwortet!

+
+ + + \ No newline at end of file diff --git a/quiz/templates/quiz.html b/quiz/templates/quiz.html new file mode 100644 index 0000000..3b1bc61 --- /dev/null +++ b/quiz/templates/quiz.html @@ -0,0 +1,124 @@ + + + + + + + + Login + + + + + +
+

{{ frage.index }}. {{ frage.question }}

+ + +

N/A von N/A beantwortet!

+
+

{{debugtxt}}

+
+ + + + \ No newline at end of file diff --git a/quiz/templates/testquiz.html b/quiz/templates/testquiz.html new file mode 100644 index 0000000..bed6656 --- /dev/null +++ b/quiz/templates/testquiz.html @@ -0,0 +1,15 @@ + + + + Quiz + + +
+ {% for qa in questions_answers %} +

{{ qa.index }}. {{ qa.question }}

+ + {% endfor %} + +
+ +