From c101a51593def5608e57b986cce1ff50855ecc4c Mon Sep 17 00:00:00 2001 From: Taeufelmaennchen <95308782+Taeufelmaennchen@users.noreply.github.com> Date: Fri, 15 Dec 2023 23:30:50 +0100 Subject: [PATCH] fragen und Antworten aus CSV --- beginner/Tester.py | 3 +- robo/choose.html | 165 +++++++++++++++++++++++++++++++++++++++++++++ robo/collect.html | 119 ++++++++++++++++++++++++++++++++ robo/csv-read.py | 41 +++++++++++ robo/fragen1.csv | 10 +++ robo/qna.html | 121 +++++++++++++++++++++++++++++++++ start.sh | 7 +- 7 files changed, 461 insertions(+), 5 deletions(-) mode change 100755 => 100644 beginner/Tester.py create mode 100644 robo/choose.html create mode 100644 robo/collect.html create mode 100644 robo/csv-read.py create mode 100644 robo/fragen1.csv create mode 100644 robo/qna.html mode change 100755 => 100644 start.sh diff --git a/beginner/Tester.py b/beginner/Tester.py old mode 100755 new mode 100644 index 908d9bb..b7e38d0 --- a/beginner/Tester.py +++ b/beginner/Tester.py @@ -5,8 +5,7 @@ import random # Liste mit Fragen und zugehörigen Antworten erstellen fragen_und_antworten = [ - {"frage": "Wie heißt die Hauptstadt von Frankreich?", - "antwort": "Paris"}, + {"frage": "Wie heißt die Hauptstadt von Frankreich?", "antwort": "Paris"}, {"frage": "Was ist die Hauptfarbe des Himmels an einem klaren Tag?", "antwort": "Blau"}, {"frage": "Wie viele Planeten gibt es in unserem Sonnensystem?", diff --git a/robo/choose.html b/robo/choose.html new file mode 100644 index 0000000..32c562e --- /dev/null +++ b/robo/choose.html @@ -0,0 +1,165 @@ + + + + + + + + + Login + + + + + +
+

Wähle eine Kategorie:

+ +
+ + + \ No newline at end of file diff --git a/robo/collect.html b/robo/collect.html new file mode 100644 index 0000000..76cadc4 --- /dev/null +++ b/robo/collect.html @@ -0,0 +1,119 @@ + + + + + + + + + Login + + + + + +
+

Richtig!
Dein BonBon ist unterwegs

+

N/A von N/A beantwortet!

+
+ + + \ No newline at end of file diff --git a/robo/csv-read.py b/robo/csv-read.py new file mode 100644 index 0000000..61d8ea5 --- /dev/null +++ b/robo/csv-read.py @@ -0,0 +1,41 @@ +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 sindin {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...") + diff --git a/robo/fragen1.csv b/robo/fragen1.csv new file mode 100644 index 0000000..f990724 --- /dev/null +++ b/robo/fragen1.csv @@ -0,0 +1,10 @@ +1;Was ist die Hauptstadt von Frankreich?;Paris +2;Wie viele Kontinente gibt es auf der Erde?;7 +3;Was ist die Hauptzutat in Spaghetti Bolognese?;Hackfleisch +4;Wie lautet die Formel für die Fläche eines Rechtecks?;a*b +5;"Welches Element hat das chemische Symbol ""H""?";Wasserstoff +6;Wie viele Planeten gibt es in unserem Sonnensystem?;8 +7;Was ist die Hauptfarbe des Himmels bei Tag?;Blau +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 \ No newline at end of file diff --git a/robo/qna.html b/robo/qna.html new file mode 100644 index 0000000..49adbb8 --- /dev/null +++ b/robo/qna.html @@ -0,0 +1,121 @@ + + + + + + + + + Login + + + + + +
+

N/A?

+ + +

N/A von N/A beantwortet!

+
+ + + \ No newline at end of file diff --git a/start.sh b/start.sh old mode 100755 new mode 100644 index e0a8d23..ec288f7 --- a/start.sh +++ b/start.sh @@ -3,7 +3,8 @@ # + Updatefunktion #GITDIR=~/git/robotSoSe2022 -GITDIR=~/git/robotik-wise23 +#GITDIR=~/git/robotik-wise23 +GITDIR=./ Choice=$( whiptail --title "Hausaufgabenrobo Start und Update" --radiolist \ "Bitte wählen" 20 78 4 \ @@ -14,8 +15,8 @@ if [ $ExitVAL = 0 ] ;then # OK case $Choice in "START") echo starte nun robot - cd $GITDIR - ./robostart.sh + cd $GITDIR/robo + python3 csv-read.py ;; "UPDATE") cd $GITDIR