enumerate questions with alphabet, convert md to pdf with docker sdk

This commit is contained in:
dechert
2021-06-15 16:58:16 +02:00
parent fe37165a23
commit 11387d34cc
3 changed files with 34 additions and 4 deletions

View File

@@ -64,10 +64,14 @@ def write_q_and_a_to_markdown_file(markdown_file, q_and_a):
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')
markdown_file.writelines(' - {}'.format(q_and_a.answerArray[i]))
alpha = alphabet[i]
markdown_file.writelines(' - {}) {}'.format(alpha, q_and_a.answerArray[i]))
markdown_file.writelines('---')
return markdown_file
@@ -88,6 +92,16 @@ def handle_q_and_a_row(line, list_of_q_and_as, category):
return list_of_q_and_as
# def to_pdf(filename):
# import docker
# client = docker.from_env()
# 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())