add category to Q and A
This commit is contained in:
		
							
								
								
									
										39
									
								
								converter.py
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								converter.py
									
									
									
									
									
								
							@@ -12,12 +12,13 @@ NUMBER_OF_ANSWERS = 5
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class QuestionAndAnswers:
 | 
					class QuestionAndAnswers:
 | 
				
			||||||
    def __init__(self, question, answerArray):
 | 
					    def __init__(self, question, answerArray, category):
 | 
				
			||||||
        self.question = question
 | 
					        self.question = question
 | 
				
			||||||
        self.answerArray = answerArray
 | 
					        self.answerArray = answerArray
 | 
				
			||||||
 | 
					        self.category = category
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        return "QuestionAndAnswers: Question: {}, Answers: {}".format(self.question, self.answerArray)
 | 
					        return "QuestionAndAnswers: Question: {}, Answers: {}, Category: {}".format(self.question, self.answerArray, self.category)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def write_markdown_file(csv_path):
 | 
					def write_markdown_file(csv_path):
 | 
				
			||||||
@@ -28,18 +29,15 @@ def write_markdown_file(csv_path):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    with open(csv_path, 'r', encoding='UTF-8') as csv_file:
 | 
					    with open(csv_path, 'r', encoding='UTF-8') as csv_file:
 | 
				
			||||||
        data = csv_file.readlines()
 | 
					        data = csv_file.readlines()
 | 
				
			||||||
 | 
					        current_category = "bla"
 | 
				
			||||||
        for line in data:
 | 
					        for line in data:
 | 
				
			||||||
        column_data = line.split(',')
 | 
					            if line.startswith("Kategorie"):
 | 
				
			||||||
        print(column_data)
 | 
					                name_of_category = line.split(",")[0]
 | 
				
			||||||
        #check size of array
 | 
					                print("name_of_category")
 | 
				
			||||||
        print(len(column_data))
 | 
					                print(name_of_category)
 | 
				
			||||||
        if len(column_data) is NUMBER_OF_ANSWERS:
 | 
					                current_category = name_of_category
 | 
				
			||||||
            question = column_data[0]
 | 
					            else:
 | 
				
			||||||
            answers = column_data[1:]  # select all elements from list except first
 | 
					                handle_q_and_a_row(line, list_of_q_and_as, current_category)
 | 
				
			||||||
            # answers = column_data[-3:]
 | 
					 | 
				
			||||||
            q_and_a = QuestionAndAnswers(question, answers)
 | 
					 | 
				
			||||||
            list_of_q_and_as.append(q_and_a)
 | 
					 | 
				
			||||||
            print(q_and_a)
 | 
					 | 
				
			||||||
        # break
 | 
					        # break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # static_part = ""
 | 
					    # static_part = ""
 | 
				
			||||||
@@ -69,3 +67,18 @@ def write_markdown_file(csv_path):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        markdown_file.close()
 | 
					        markdown_file.close()
 | 
				
			||||||
    # return filename
 | 
					    # return filename
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def handle_q_and_a_row(line, list_of_q_and_as, category):
 | 
				
			||||||
 | 
					    column_data = line.split(',')
 | 
				
			||||||
 | 
					    print(column_data)
 | 
				
			||||||
 | 
					    # check size of array
 | 
				
			||||||
 | 
					    print(len(column_data))
 | 
				
			||||||
 | 
					    if len(column_data) is NUMBER_OF_ANSWERS:
 | 
				
			||||||
 | 
					        question = column_data[0]
 | 
				
			||||||
 | 
					        answers = column_data[1:]  # select all elements from list except first
 | 
				
			||||||
 | 
					        # answers = column_data[-3:]
 | 
				
			||||||
 | 
					        q_and_a = QuestionAndAnswers(question, answers, category)
 | 
				
			||||||
 | 
					        list_of_q_and_as.append(q_and_a)
 | 
				
			||||||
 | 
					        print(q_and_a)
 | 
				
			||||||
 | 
					    return list_of_q_and_as
 | 
				
			||||||
							
								
								
									
										11
									
								
								quiz-example-with-category.csv
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								quiz-example-with-category.csv
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					Kategorie 1: Zitate ( Wer hat's gesagt?),,,,
 | 
				
			||||||
 | 
					(1) Probleme sind nur Dorninge Chancen,Jan Böhmermann,Christian Lindner,Elon Musk,Pable Escobar
 | 
				
			||||||
 | 
					(2) Niemand hat die Absicht eine Mauer zu errichten,Erich Honecker,Lothar de Maizière,Walter Ulbricht,Donald Trump
 | 
				
			||||||
 | 
					(3) Auf den Alkohol – den Ursprung und die Lösung sämtlicher Lebensprobleme,Boris Jelzin,Homer Simpson,Prinz Harry,Charlie Sheen
 | 
				
			||||||
 | 
					"(4) Ich so zu mein homie: ich komme später, ich steck noch im Verkehr Er: mit dem Auto? Ich: nein in 1 bitch. Geschlechtsverkehr!",Moneyboy,Oliver Pocher,Manny Marc,Dieter Bohlen
 | 
				
			||||||
 | 
					(5) Aus großer Macht folgt große Verantwortung.,Neil Armstrong,Jesus Christus,Chuck Norris,Ben Parker aus Spiderman
 | 
				
			||||||
 | 
					"(6) Wenn ich über steuer- und erbrechtliche Anerkennung von homosexuellen Paaren diskutiere, dann kann ich gleich über Teufelsanbetung diskutieren.",Rainer Maria Woelki,Papst Benedikt XVI,Friedrich Merz,Edmund Stoiber
 | 
				
			||||||
 | 
					"(7) Mir hat auch niemand gesagt, wie man Kapitalist wird.",Dagobert Duck,Christian Lindner,Jeff Bezos,Queen Elisabeth II.
 | 
				
			||||||
 | 
					"(8) Geh dein Weg, leb dein Leben, sei du selbst, Fick deine Mutter",Money Boy,Farid Bang,KIZ (wer von denen?),Immanuel Kant
 | 
				
			||||||
 | 
					(9) Man muss Gesetze kompliziert machen. Dann fällt es nicht so auf.,Horst Seehofer,Wladimir Putin,Erich Honecker,Boris Johnson
 | 
				
			||||||
 | 
					"(10) Chef sein ist wie ein Wecker. Keiner will ihn, jeder hasst ihn, aber wenn er nicht da ist, dann machen alle Schnarch.",Paul Ditter,Bernd Stromberg,Markus Stockschläder,Jürgen Klopp
 | 
				
			||||||
		
		
			
  | 
							
								
								
									
										12
									
								
								tests.py
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								tests.py
									
									
									
									
									
								
							@@ -5,14 +5,22 @@ import shutil
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import converter
 | 
					import converter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestDiary(unittest.TestCase):
 | 
					class TestDiary(unittest.TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # BASE_FODLER = "test_data"
 | 
					    # BASE_FODLER = "test_data"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_create_month_file_january(self):
 | 
					    # def test_basic_csv_input(self):
 | 
				
			||||||
 | 
					    #     # python command_line 2021-01
 | 
				
			||||||
 | 
					    #     BASE_FODLER = "test_data"
 | 
				
			||||||
 | 
					    #     converter.write_markdown_file('quiz-example.csv')
 | 
				
			||||||
 | 
					    #     # assert file was created
 | 
				
			||||||
 | 
					    #     assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md")))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_csv_input_with_categories(self):
 | 
				
			||||||
        # python command_line 2021-01
 | 
					        # python command_line 2021-01
 | 
				
			||||||
        BASE_FODLER = "test_data"
 | 
					        BASE_FODLER = "test_data"
 | 
				
			||||||
        converter.write_markdown_file('quiz-example.csv')
 | 
					        converter.write_markdown_file('quiz-example-with-category.csv')
 | 
				
			||||||
        # assert file was created
 | 
					        # assert file was created
 | 
				
			||||||
        assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md")))
 | 
					        assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md")))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user