basically working
This commit is contained in:
parent
ba9d85def1
commit
7ec4a56d53
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
10
README.md
10
README.md
@ -1,3 +1,11 @@
|
||||
# csv-to-marp-converter
|
||||
|
||||
multiple-choice-quiz-csv-to-marp-markdown-slides-converter
|
||||
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
|
||||
|
||||
|
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
|
10
quiz-example.csv
Normal file
10
quiz-example.csv
Normal file
@ -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
|
|
24
quiz-slides-template.md
Normal file
24
quiz-slides-template.md
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
marp: true
|
||||
theme: gaia
|
||||
# class:
|
||||
# - lead
|
||||
# - invert
|
||||
---
|
||||
|
||||
<!--
|
||||
Styling the Theme:
|
||||
https://github.com/marp-team/marp-core/tree/main/themes -->
|
||||
<style>
|
||||
:root {
|
||||
--color-background: #ddd !important;
|
||||
--color-foreground: #333 !important;
|
||||
--color-highlight: #f96 !important;
|
||||
--color-dimmed: #888 !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
# Quiz
|
||||
<!-- INSERT NAME OF QUIZ HERE -->
|
||||
|
||||
---
|
0
requirements.txt
Normal file
0
requirements.txt
Normal file
42
tests.py
Normal file
42
tests.py
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user