diff --git a/README.md b/README.md index 4145527..da89490 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ multiple-choice-quiz-csv-to-marp-markdown-slides-converter +this tool can convert a csv file into a [Marp](https://marpit.marp.app/) markdown slides, which can subsequently be converted into a pdf file. csv needs to have the following format ```` @@ -10,7 +11,6 @@ Kategorie 1: Zitate ( Wer hat's gesagt?),,,, ```` Strings surrounded with quotation marks - docker run --rm --init -v $PWD:/home/marp/app/ -e LANG=$LANG marpteam/marp-cli slide-deck.md --pdf powerpoint export is also possible with --pptx diff --git a/converter.py b/converter.py index 34d92c6..4c8f146 100644 --- a/converter.py +++ b/converter.py @@ -1,14 +1,13 @@ -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 +BASE_FODLER = "test_data" class QuestionAndAnswers: @@ -23,19 +22,22 @@ class QuestionAndAnswers: def convert(csv_path, output_pdf=False): write_markdown_file(csv_path) - if(output_pdf): + if (output_pdf): to_pdf("slide-deck.md") def write_markdown_file(csv_path): # csv_path = "quiz-example.csv" - markdown_path = "slide-deck.md" + OUTPUT_FODLER = "output" + markdown_filename = "slide-deck.md" + markdown_path = os.path.join(OUTPUT_FODLER, markdown_filename) + # read CSV list_of_q_and_as = [] with open(csv_path, 'r', encoding='UTF-8') as csv_file: data = csv_file.readlines() - current_category = "bla" + current_category = "" for line in data: if line.startswith("Kategorie"): name_of_category = line.split(",")[0] @@ -108,8 +110,12 @@ def to_pdf(filename): client = docker.from_env() current_dir = os.getcwd() print(current_dir) + + OUTPUT_FODLER = "output" + output_folder_path = os.path.join(current_dir, OUTPUT_FODLER) + # https://docker-py.readthedocs.io/en/stable/containers.html - client.containers.run('marpteam/marp-cli', '{} --pdf'.format(filename), volumes=[current_dir + ':/home/marp/app/'], + client.containers.run('marpteam/marp-cli', '{} --pdf'.format(filename), volumes=[output_folder_path + ':/home/marp/app/'], name="marp", detach=True, remove=True, init=True) container = client.containers.get('marp') diff --git a/quiz-example-with-category-and-empty-rows.csv b/test_data/quiz-example-with-category-and-empty-rows.csv similarity index 84% rename from quiz-example-with-category-and-empty-rows.csv rename to test_data/quiz-example-with-category-and-empty-rows.csv index 511433e..b579b66 100644 --- a/quiz-example-with-category-and-empty-rows.csv +++ b/test_data/quiz-example-with-category-and-empty-rows.csv @@ -2,13 +2,13 @@ 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 +(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 +(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 +(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 ,,,, Kategorie 2: Unnützes Wissen,,,, (1) Was wird als Ursache für die beschleunigte Expansion des Universums vermutet?,Antimaterie,Dunkle Materie,Dunkle Energie,Schwarze Magie diff --git a/quiz-example-with-category.csv b/test_data/quiz-example-with-category.csv similarity index 100% rename from quiz-example-with-category.csv rename to test_data/quiz-example-with-category.csv diff --git a/quiz-example.csv b/test_data/quiz-example.csv similarity index 100% rename from quiz-example.csv rename to test_data/quiz-example.csv diff --git a/tests.py b/tests.py index b276aed..4231acc 100644 --- a/tests.py +++ b/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import os import unittest -import shutil +from time import sleep import converter @@ -10,49 +10,55 @@ class TestDiary(unittest.TestCase): # BASE_FODLER = "test_data" - # 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_basic_csv_input(self): + # python command_line 2021-01 + BASE_FODLER = "test_data" + OUTPUT_FODLER = "output" + + file_path = os.path.join(BASE_FODLER, "quiz-example.csv") + converter.write_markdown_file(file_path) + # assert file was created + assert (os.path.exists(os.path.join(OUTPUT_FODLER, "slide-deck.md"))) def test_csv_input_with_categories(self): # python command_line 2021-01 BASE_FODLER = "test_data" - converter.write_markdown_file('quiz-example-with-category.csv') + OUTPUT_FODLER = "output" + + file_path = os.path.join(BASE_FODLER, "quiz-example-with-category.csv") + # converter.write_markdown_file('test_data/quiz-example-with-category.csv') + converter.write_markdown_file(file_path) # assert file was created - assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md"))) + assert (os.path.exists(os.path.join(OUTPUT_FODLER, "slide-deck.md"))) def test_csv_input_with_categories_and_empty_rows(self): # python command_line 2021-01 BASE_FODLER = "test_data" - converter.write_markdown_file('quiz-example-with-category-and-empty-rows.csv') + OUTPUT_FODLER = "output" + + file_path = os.path.join(BASE_FODLER, "quiz-example-with-category-and-empty-rows.csv") + converter.write_markdown_file(file_path) # assert file was created - assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md"))) + assert (os.path.exists(os.path.join(OUTPUT_FODLER, "slide-deck.md"))) def test_to_pdf(self): # python command_line 2021-01 - BASE_FODLER = "test_data" + OUTPUT_FODLER = "output" converter.to_pdf("slide-deck.md") + sleep(5) # wait for docker container to finish conversion # assert file was created - assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md"))) + assert (os.path.exists(os.path.join(OUTPUT_FODLER, "slide-deck.pdf"))) - # def test_create_month_file_january(self): - # # python command_line 2021-01 - # BASE_FODLER = "test_data" - # diary.parse_input('2021-01', BASE_FODLER) - # # assert file was created - # assert(os.path.exists(os.path.join(BASE_FODLER, "01_2021.md"))) + def setUp(self): + print("test started...") + BASE_FODLER = "test_data" + OUTPUT_FODLER = "output" - - # def setUp(self): - # print("test started...") - # BASE_FODLER = "test_data" - # # bla = os.path.join(BASE_FODLER, "12_2020.md") - # if not os.path.exists(BASE_FODLER): - # os.makedirs(BASE_FODLER) + if not os.path.exists(BASE_FODLER): + os.makedirs(BASE_FODLER) + if not os.path.exists(OUTPUT_FODLER): + os.makedirs(OUTPUT_FODLER) # def tearDown(self): # # pass