Compare commits
No commits in common. "11387d34cca88e9acf5a28376732af4add9b5933" and "ec4135035def6c817a323689ac8bd0936b822d42" have entirely different histories.
11387d34cc
...
ec4135035d
@ -3,14 +3,6 @@
|
|||||||
multiple-choice-quiz-csv-to-marp-markdown-slides-converter
|
multiple-choice-quiz-csv-to-marp-markdown-slides-converter
|
||||||
|
|
||||||
|
|
||||||
csv needs to have the following format
|
|
||||||
````
|
|
||||||
Kategorie 1: Zitate ( Wer hat's gesagt?),,,,
|
|
||||||
(1) Probleme sind nur Dorninge Chancen,Jan Böhmermann,Christian Lindner,Elon Musk,Pable Escobar
|
|
||||||
````
|
|
||||||
Strings surrounded with quotation marks
|
|
||||||
|
|
||||||
|
|
||||||
docker run --rm --init -v $PWD:/home/marp/app/ -e LANG=$LANG marpteam/marp-cli slide-deck.md --pdf
|
docker run --rm --init -v $PWD:/home/marp/app/ -e LANG=$LANG marpteam/marp-cli slide-deck.md --pdf
|
||||||
|
|
||||||
Script to run:
|
Script to run:
|
||||||
|
88
converter.py
88
converter.py
@ -12,13 +12,12 @@ NUMBER_OF_ANSWERS = 5
|
|||||||
|
|
||||||
|
|
||||||
class QuestionAndAnswers:
|
class QuestionAndAnswers:
|
||||||
def __init__(self, question, answerArray, category):
|
def __init__(self, question, answerArray):
|
||||||
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: {}, Category: {}".format(self.question, self.answerArray, self.category)
|
return "QuestionAndAnswers: Question: {}, Answers: {}".format(self.question, self.answerArray)
|
||||||
|
|
||||||
|
|
||||||
def write_markdown_file(csv_path):
|
def write_markdown_file(csv_path):
|
||||||
@ -29,15 +28,18 @@ 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 = ""
|
||||||
@ -52,56 +54,18 @@ def write_markdown_file(csv_path):
|
|||||||
# markdown_file.writelines(static_part)
|
# markdown_file.writelines(static_part)
|
||||||
for q_and_a in list_of_q_and_as:
|
for q_and_a in list_of_q_and_as:
|
||||||
print(q_and_a)
|
print(q_and_a)
|
||||||
write_q_and_a_to_markdown_file(markdown_file, q_and_a)
|
markdown_file.writelines('\n')
|
||||||
|
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.writelines('---')
|
||||||
|
|
||||||
markdown_file.close()
|
markdown_file.close()
|
||||||
# return filename
|
# return filename
|
||||||
|
|
||||||
|
|
||||||
def write_q_and_a_to_markdown_file(markdown_file, q_and_a):
|
|
||||||
markdown_file.writelines('\n')
|
|
||||||
markdown_file.writelines('# {}'.format(q_and_a.category))
|
|
||||||
markdown_file.writelines('\n')
|
|
||||||
markdown_file.writelines('## {}'.format(q_and_a.question))
|
|
||||||
|
|
||||||
import string
|
|
||||||
alphabet = string.ascii_lowercase
|
|
||||||
|
|
||||||
# for i, obj in q_and_a.answerArray:
|
|
||||||
for i, obj in enumerate(q_and_a.answerArray):
|
|
||||||
markdown_file.writelines('\n')
|
|
||||||
alpha = alphabet[i]
|
|
||||||
markdown_file.writelines(' - {}) {}'.format(alpha, q_and_a.answerArray[i]))
|
|
||||||
|
|
||||||
markdown_file.writelines('---')
|
|
||||||
return markdown_file
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
# docker run --rm --init -v $PWD:/home/marp/app/ -e LANG=$LANG marpteam/marp-cli slide-deck.md --pdf
|
|
||||||
# minimal (windows): docker run -v ${PWD}:/home/marp/app/ marpteam/marp-cli slide-deck.md --pdf
|
|
||||||
def to_pdf(filename):
|
|
||||||
import docker
|
|
||||||
client = docker.from_env()
|
|
||||||
current_dir = os.getcwd()
|
|
||||||
print(current_dir)
|
|
||||||
# https://docker-py.readthedocs.io/en/stable/containers.html
|
|
||||||
client.containers.run('marpteam/marp-cli', '{} --pdf'.format(filename), volumes=[current_dir + ':/home/marp/app/'],
|
|
||||||
name="marp", detach=True, remove=True, init=True)
|
|
||||||
|
|
||||||
container = client.containers.get('marp')
|
|
||||||
print(container.logs())
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
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
|
|
|
@ -1,8 +0,0 @@
|
|||||||
certifi==2021.5.30
|
|
||||||
chardet==4.0.0
|
|
||||||
docker==5.0.0
|
|
||||||
idna==2.10
|
|
||||||
pywin32==227
|
|
||||||
requests==2.25.1
|
|
||||||
urllib3==1.26.5
|
|
||||||
websocket-client==1.1.0
|
|
20
tests.py
20
tests.py
@ -5,30 +5,14 @@ import shutil
|
|||||||
|
|
||||||
import converter
|
import converter
|
||||||
|
|
||||||
|
|
||||||
class TestDiary(unittest.TestCase):
|
class TestDiary(unittest.TestCase):
|
||||||
|
|
||||||
# BASE_FODLER = "test_data"
|
# BASE_FODLER = "test_data"
|
||||||
|
|
||||||
# def test_basic_csv_input(self):
|
def test_create_month_file_january(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-with-category.csv')
|
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_to_pdf(self):
|
|
||||||
# python command_line 2021-01
|
|
||||||
BASE_FODLER = "test_data"
|
|
||||||
converter.to_pdf("slide-deck.md")
|
|
||||||
|
|
||||||
# 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")))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user