basically working
This commit is contained in:
67
converter.py
Normal file
67
converter.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import calendar
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
# def file_exists(filename):
|
||||
# if os.path.exists(filename):
|
||||
# print('Note: Diary \'' + filename + '\' already exists. Will not be modified.')
|
||||
# return True
|
||||
# return False
|
||||
NUMBER_OF_ANSWERS = 5
|
||||
|
||||
|
||||
class QuestionAndAnswers:
|
||||
def __init__(self, question, answerArray):
|
||||
self.question = question
|
||||
self.answerArray = answerArray
|
||||
|
||||
def __str__(self):
|
||||
return "QuestionAndAnswers: Question: {}, Answers: {}".format(self.question, self.answerArray)
|
||||
|
||||
|
||||
def write_markdown_file(csv_path):
|
||||
# csv_path = "quiz-example.csv"
|
||||
markdown_path = "slide-deck.md"
|
||||
# read CSV
|
||||
list_of_q_and_as = []
|
||||
|
||||
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)
|
||||
break
|
||||
|
||||
static_part = ""
|
||||
template_name = "quiz-slides-template.md"
|
||||
shutil.copyfile(template_name, markdown_path)
|
||||
|
||||
# with open(markdown_path, 'w', encoding='UTF-8') as markdown_file:
|
||||
with open(markdown_path, 'a', encoding='UTF-8') as markdown_file:
|
||||
# write month headline
|
||||
markdown_file.writelines(static_part)
|
||||
for q_and_a in list_of_q_and_as:
|
||||
print(q_and_a)
|
||||
markdown_file.writelines('# {}'.format(q_and_a.question))
|
||||
markdown_file.writelines('\n')
|
||||
markdown_file.writelines(' - {}'.format(q_and_a.answerArray[0]))
|
||||
markdown_file.writelines('\n')
|
||||
markdown_file.writelines(' - {}'.format(q_and_a.answerArray[1]))
|
||||
markdown_file.writelines('\n')
|
||||
markdown_file.writelines(' - {}'.format(q_and_a.answerArray[2]))
|
||||
markdown_file.writelines('\n')
|
||||
markdown_file.writelines(' - {}'.format(q_and_a.answerArray[3]))
|
||||
markdown_file.writelines('\n')
|
||||
|
||||
markdown_file.close()
|
||||
# return filename
|
||||
Reference in New Issue
Block a user