doit
This commit is contained in:
1 parent
e9a1261423
commit
ccbf300047
7 files changed
+470
-35
No files matched your search
@@ -1,3 +1,6 @@
|
|||||||
FLASK_APP=quiz.py
|
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
|
FLASK_RUN_PORT=5003
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Quiz</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form method="POST" action="/submit_quiz">
|
|
||||||
{% for question in q_a %}
|
|
||||||
<p>{{ question.question }}</p>
|
|
||||||
<!-- {% for answer in question.answers %}
|
|
||||||
<input type="radio" name="question{{ loop.index }}" value="{{ answer }}"> {{ answer }}<br>
|
|
||||||
{% endfor %} -->
|
|
||||||
<p>{{ question.answer }}</p>
|
|
||||||
{% endfor %}
|
|
||||||
<input type="submit" value="Quiz abschicken">
|
|
||||||
</form>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
+43
-16
@@ -1,11 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
from flask import Flask, render_template
|
from flask import Flask, redirect, render_template, request, session
|
||||||
from dotenv import load_dotenv
|
|
||||||
import csv # CSV handling
|
import csv # CSV handling
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
load_dotenv() # Laden Sie die Umgebungsvariablen aus der .env-Datei
|
|
||||||
|
|
||||||
def load_database():
|
def load_database():
|
||||||
file = os.path.join(os.path.expanduser("~"), "Austausch", "fragen1.csv")
|
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)
|
answer = str(row[2]) # Antwort (3. Spalte in der CSV Datenbank)
|
||||||
q_a.append({"index": index,"question": question, "answer": answer}) # Eine Liste bauen
|
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('/')
|
@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__':
|
def quiz():
|
||||||
# app.run(debug=True)
|
|
||||||
load_database()
|
return render_template('quiz.html', frage=fragen_liste[current_index],last_correct=last_correct,debugtxt=debugtxt)
|
||||||
port = int(os.getenv("FLASK_RUN_PORT", 5000))
|
|
||||||
app.run(debug=True,host="0.0.0.0", port=port)
|
@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 += "<!-- user_answer = " + user_answer + " -->\n"
|
||||||
|
# debugtxt += "<!-- correct_anwer = " + correct_answer + " -->\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('/')
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<!-- <link rel="stylesheet" href="../.data/style/forms.css">
|
||||||
|
<link rel="stylesheet" href="../.data/style/main.css"> -->
|
||||||
|
<title>Login</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Arial', sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100dvh;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: linear-gradient(315deg, rgb(134, 65, 163) 0%, rgb(196, 99, 238) 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
width: 300px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
transition: box-shadow 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
form:hover {
|
||||||
|
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: rgb(102, 51, 153);
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
background-color: transparent !important;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid rgb(142, 68, 173, 0.25);
|
||||||
|
outline: none;
|
||||||
|
transition: border-bottom 0.3s ease-in-out;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus,
|
||||||
|
input:hover {
|
||||||
|
border-bottom: 1px solid rgb(142, 68, 173, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
input+label {
|
||||||
|
position: absolute;
|
||||||
|
top: 8px;
|
||||||
|
left: 8px;
|
||||||
|
color: #8E44AD;
|
||||||
|
transition: top 0.3s ease-in-out, font-size 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus+label,
|
||||||
|
input:not(:placeholder-shown)+label {
|
||||||
|
top: -14px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-color: rgb(106, 90, 205);
|
||||||
|
color: rgb(255, 255, 255);
|
||||||
|
padding: 10px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
transition: background-color 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: rgb(72, 61, 139);
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
color: rgb(106, 90, 205);
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.q-amount {
|
||||||
|
font-size: small;
|
||||||
|
color: rgb(180, 180, 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: rgb(106, 90, 205);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
li a {text-decoration : none; color : #2d2f31;}
|
||||||
|
|
||||||
|
nav {
|
||||||
|
width : input;
|
||||||
|
background: #d9d9d9;
|
||||||
|
margin : 40px auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
padding : 30px;
|
||||||
|
background : #2d2f31;
|
||||||
|
color : white;
|
||||||
|
font-size : 1.2em;
|
||||||
|
font-variant : small-caps;
|
||||||
|
cursor : pointer;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
span::after {
|
||||||
|
float: right;
|
||||||
|
right: 10%;
|
||||||
|
content: "+";
|
||||||
|
}
|
||||||
|
|
||||||
|
.slide {
|
||||||
|
clear:both;
|
||||||
|
width:100%;
|
||||||
|
height:0px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
transition: height .4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slide li {
|
||||||
|
padding : 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#touch {
|
||||||
|
position: absolute; opacity: 0; height: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#touch:checked +
|
||||||
|
.slide {
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form method="post" action="">
|
||||||
|
<p>Wähle eine Kategorie:</p>
|
||||||
|
<button type="submit">Wählen</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<!-- <link rel="stylesheet" href="../.data/style/forms.css">
|
||||||
|
<link rel="stylesheet" href="../.data/style/main.css"> -->
|
||||||
|
<title>{{htmltitle}}</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Arial', sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100dvh;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: linear-gradient(315deg, rgb(134, 65, 163) 0%, rgb(196, 99, 238) 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
width: 300px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
transition: box-shadow 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
form:hover {
|
||||||
|
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: rgb(102, 51, 153);
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
background-color: transparent !important;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid rgb(142, 68, 173, 0.25);
|
||||||
|
outline: none;
|
||||||
|
transition: border-bottom 0.3s ease-in-out;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus,
|
||||||
|
input:hover {
|
||||||
|
border-bottom: 1px solid rgb(142, 68, 173, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
input+label {
|
||||||
|
position: absolute;
|
||||||
|
top: 8px;
|
||||||
|
left: 8px;
|
||||||
|
color: #8E44AD;
|
||||||
|
transition: top 0.3s ease-in-out, font-size 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus+label,
|
||||||
|
input:not(:placeholder-shown)+label {
|
||||||
|
top: -14px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-color: rgb(106, 90, 205);
|
||||||
|
color: rgb(255, 255, 255);
|
||||||
|
padding: 10px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
transition: background-color 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: rgb(72, 61, 139);
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
color: rgb(106, 90, 205);
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.q-amount {
|
||||||
|
font-size: small;
|
||||||
|
color: rgb(180, 180, 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: rgb(106, 90, 205);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<p><strong>Richtig!</strong><br>Dein BonBon ist unterwegs</p>
|
||||||
|
<p class="q-amount">N/A von N/A beantwortet!</p>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<!-- <link rel="stylesheet" href="../.data/style/forms.css">
|
||||||
|
<link rel="stylesheet" href="../.data/style/main.css"> -->
|
||||||
|
<title>Login</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Arial', sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100dvh;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: linear-gradient(315deg, rgb(134, 65, 163) 0%, rgb(196, 99, 238) 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
width: 300px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
transition: box-shadow 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
form:hover {
|
||||||
|
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: rgb(102, 51, 153);
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
background-color: transparent !important;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid rgb(142, 68, 173, 0.25);
|
||||||
|
outline: none;
|
||||||
|
transition: border-bottom 0.3s ease-in-out;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus,
|
||||||
|
input:hover {
|
||||||
|
border-bottom: 1px solid rgb(142, 68, 173, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
input+label {
|
||||||
|
position: absolute;
|
||||||
|
top: 8px;
|
||||||
|
left: 8px;
|
||||||
|
color: #8E44AD;
|
||||||
|
transition: top 0.3s ease-in-out, font-size 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus+label,
|
||||||
|
input:not(:placeholder-shown)+label {
|
||||||
|
top: -14px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-color: rgb(106, 90, 205);
|
||||||
|
color: rgb(255, 255, 255);
|
||||||
|
padding: 10px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
transition: background-color 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: rgb(72, 61, 139);
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
color: rgb(106, 90, 205);
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.q-amount {
|
||||||
|
font-size: small;
|
||||||
|
color: rgb(180, 180, 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: rgb(106, 90, 205);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form method="POST" action="/submit_quiz">
|
||||||
|
<p name="question">{{ frage.index }}. {{ frage.question }}</p>
|
||||||
|
<input type="text" name="answer" placeholder="Antwort eingeben..." required>
|
||||||
|
<input type="submit" value="Quiz abschicken">
|
||||||
|
<p class="q-amount">N/A von N/A beantwortet!</p>
|
||||||
|
<br />
|
||||||
|
<p class="debug">{{debugtxt}}</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Quiz</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form method="POST" action="/submit_quiz">
|
||||||
|
{% for qa in questions_answers %}
|
||||||
|
<p>{{ qa.index }}. {{ qa.question }}</p>
|
||||||
|
<input type="text" name="answer{{ qa.index }}" required>
|
||||||
|
{% endfor %}
|
||||||
|
<input type="submit" value="Quiz abschicken">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in new issue
Block a user