ignor und upload flasK
This commit is contained in:
1 parent
294a15cb8e
commit
e9a1261423
8 files changed
+118
-3
No files matched your search
+1
-1
@@ -1 +1 @@
|
||||
quiz/__pycache__/
|
||||
quiz/__pycache__
|
||||
@@ -0,0 +1,47 @@
|
||||
import csv # CSV handling
|
||||
import random
|
||||
import os
|
||||
|
||||
#file = "C:/Users/bruno/Documents/__CODING__/0-git (Group)/robotik-wise23/robo/fragen1.csv"
|
||||
#file = os.getcwd() + "fragen1.csv"
|
||||
#file = os.path.join(os.getcwd(), "robo", "fragen1.csv") # Windows Entwicklung
|
||||
file = os.path.join(os.getcwd(), "fragen1.csv") # Raspi
|
||||
|
||||
#with open(file, newline="", encoding="utf-8") as csvfile: #
|
||||
with open(file, newline="", encoding="cp1252") as csvfile: # Code wird als Excel Windows-1252 Input CSV gelesen
|
||||
database = csv.reader(csvfile, delimiter=";") # Validating the "csvfile" into "database" with the delimiter "," (Comma Seperated Values)
|
||||
|
||||
q_a = [] # Empty list for all questions and answers
|
||||
|
||||
for row in database: # alle Zeilen in der Datenbank durchlaufen
|
||||
index = int(row[0]) # Laufende Nummer
|
||||
question = str(row[1]) # Frage (ist der erste Teil)
|
||||
answer = str(row[2]) # Antwort (3. Spalte in der CSV Datenbank)
|
||||
q_a.append({"index": index,"question": question, "answer": answer}) # Eine Liste bauen
|
||||
|
||||
# for i in q_a: # For every element in "q_a"
|
||||
# print("[" + str(i["index"]) + "] Frage: " + i["question"] + "\n[" + str(i["index"]) + "] Antwort: " + i["answer"] + "\n") # Print "question", "answer" and "index" for current element
|
||||
|
||||
|
||||
while True:
|
||||
# Zufällig eine Frage auswählen
|
||||
zufallige_frage = random.choice(q_a)
|
||||
ID = zufallige_frage["index"]
|
||||
frage = zufallige_frage["question"]
|
||||
antwort = zufallige_frage["answer"]
|
||||
|
||||
#print(f"wir sind in {os.getcwd()}")
|
||||
|
||||
# Frage und Antwort ausgeben
|
||||
print(f"Frage:\t({ID})\t{frage}")
|
||||
# print(f"Antwort:\t{antwort}")
|
||||
|
||||
# Auf Eingabe warten
|
||||
# input("Drücke Enter für die nächste Frage...")
|
||||
DieAntwort= input(" > ")
|
||||
if ( DieAntwort == antwort ):
|
||||
print ("Sehr gut!")
|
||||
else :
|
||||
print ("Nein! Nochmal. (Setzen, 6) ")
|
||||
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
.env
|
||||
@@ -0,0 +1,18 @@
|
||||
<!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>
|
||||
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
from flask import Flask, render_template
|
||||
from dotenv import load_dotenv
|
||||
import csv # CSV handling
|
||||
import random
|
||||
|
||||
|
||||
load_dotenv() # Laden Sie die Umgebungsvariablen aus der .env-Datei
|
||||
|
||||
def load_database():
|
||||
file = os.path.join(os.path.expanduser("~"), "Austausch", "fragen1.csv")
|
||||
|
||||
#with open(file, newline="", encoding="utf-8") as csvfile: #
|
||||
with open(file, newline="", encoding="cp1252") as csvfile: # Code wird als Excel Windows-1252 Input CSV gelesen
|
||||
database = csv.reader(csvfile, delimiter=";") # Validating the "csvfile" into "database" with the delimiter "," (Comma Seperated Values)
|
||||
|
||||
q_a = [] # Empty list for all questions and answers
|
||||
|
||||
for row in database: # alle Zeilen in der Datenbank durchlaufen
|
||||
index = int(row[0]) # Laufende Nummer
|
||||
question = str(row[1]) # Frage (ist der erste Teil)
|
||||
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__)
|
||||
|
||||
@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)
|
||||
+8
-2
@@ -34,8 +34,14 @@ while True:
|
||||
|
||||
# Frage und Antwort ausgeben
|
||||
print(f"Frage:\t({ID})\t{frage}")
|
||||
print(f"Antwort:\t{antwort}")
|
||||
# print(f"Antwort:\t{antwort}")
|
||||
|
||||
# Auf Eingabe warten
|
||||
input("Drücke Enter für die nächste Frage...")
|
||||
# input("Drücke Enter für die nächste Frage...")
|
||||
DieAntwort= input(" > ")
|
||||
if ( DieAntwort == antwort ):
|
||||
print ("Sehr gut!")
|
||||
else :
|
||||
print ("Nein! Nochmal. (Setzen, 6) ")
|
||||
|
||||
|
||||
@@ -8,3 +8,4 @@
|
||||
8;Welches Jahr wurde die Unabhängigkeit der USA erklärt?;1776
|
||||
9;Welches ist das größte Säugetier der Welt?;Blauwal
|
||||
10;Wie viele Sekunden hat eine Minute?;60
|
||||
11;Was sind m&ms ?;Die Belohnung
|
||||
|
Reference in new issue
Block a user