From 7ec4a56d5314f64393fb316e1b75b53fc8e80897 Mon Sep 17 00:00:00 2001 From: dechert Date: Tue, 15 Jun 2021 15:46:38 +0200 Subject: [PATCH] basically working --- .idea/.gitignore | 3 ++ README.md | 10 +++++- converter.py | 67 +++++++++++++++++++++++++++++++++++++++++ quiz-example.csv | 10 ++++++ quiz-slides-template.md | 24 +++++++++++++++ requirements.txt | 0 tests.py | 42 ++++++++++++++++++++++++++ 7 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 converter.py create mode 100644 quiz-example.csv create mode 100644 quiz-slides-template.md create mode 100644 requirements.txt create mode 100644 tests.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/README.md b/README.md index 1fa8e53..06acc3f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # csv-to-marp-converter -multiple-choice-quiz-csv-to-marp-markdown-slides-converter \ No newline at end of file +multiple-choice-quiz-csv-to-marp-markdown-slides-converter + + +docker run --rm --init -v $PWD:/home/marp/app/ -e LANG=$LANG marpteam/marp-cli slide-deck.md --pdf + +Script to run: +1. csv -> marp markdown converter +2. md -> pdf conversion using mark cli docker image + diff --git a/converter.py b/converter.py new file mode 100644 index 0000000..0db85c9 --- /dev/null +++ b/converter.py @@ -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 diff --git a/quiz-example.csv b/quiz-example.csv new file mode 100644 index 0000000..634a6e3 --- /dev/null +++ b/quiz-example.csv @@ -0,0 +1,10 @@ +(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 diff --git a/quiz-slides-template.md b/quiz-slides-template.md new file mode 100644 index 0000000..d5a15c4 --- /dev/null +++ b/quiz-slides-template.md @@ -0,0 +1,24 @@ +--- +marp: true +theme: gaia +# class: + # - lead + # - invert +--- + + + + +# Quiz + + +--- diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..f55f94a --- /dev/null +++ b/tests.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +import os +import unittest +import shutil + +import converter + +class TestDiary(unittest.TestCase): + + # BASE_FODLER = "test_data" + + 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_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" + # # bla = os.path.join(BASE_FODLER, "12_2020.md") + # if not os.path.exists(BASE_FODLER): + # os.makedirs(BASE_FODLER) + + # def tearDown(self): + # # pass + # BASE_FODLER = "test_data" + # if os.path.exists(BASE_FODLER): + # shutil.rmtree(BASE_FODLER) # remove testing garbage folder + + +if __name__ == '__main__': + unittest.main()