add category to Q and A
This commit is contained in:
41
converter.py
41
converter.py
@@ -12,12 +12,13 @@ NUMBER_OF_ANSWERS = 5
|
||||
|
||||
|
||||
class QuestionAndAnswers:
|
||||
def __init__(self, question, answerArray):
|
||||
def __init__(self, question, answerArray, category):
|
||||
self.question = question
|
||||
self.answerArray = answerArray
|
||||
self.category = category
|
||||
|
||||
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):
|
||||
@@ -28,18 +29,15 @@ def write_markdown_file(csv_path):
|
||||
|
||||
with open(csv_path, 'r', encoding='UTF-8') as csv_file:
|
||||
data = csv_file.readlines()
|
||||
for line in data:
|
||||
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)
|
||||
list_of_q_and_as.append(q_and_a)
|
||||
print(q_and_a)
|
||||
current_category = "bla"
|
||||
for line in data:
|
||||
if line.startswith("Kategorie"):
|
||||
name_of_category = line.split(",")[0]
|
||||
print("name_of_category")
|
||||
print(name_of_category)
|
||||
current_category = name_of_category
|
||||
else:
|
||||
handle_q_and_a_row(line, list_of_q_and_as, current_category)
|
||||
# break
|
||||
|
||||
# static_part = ""
|
||||
@@ -69,3 +67,18 @@ def write_markdown_file(csv_path):
|
||||
|
||||
markdown_file.close()
|
||||
# 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
|
||||
Reference in New Issue
Block a user