From ec4135035def6c817a323689ac8bd0936b822d42 Mon Sep 17 00:00:00 2001 From: dechert Date: Tue, 15 Jun 2021 15:56:07 +0200 Subject: [PATCH] add command line interface --- .gitignore | 3 +++ command_line.py | 23 +++++++++++++++++++++++ converter.py | 10 +++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 command_line.py diff --git a/.gitignore b/.gitignore index f8b73e7..0a6e27e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.idea +csvmarp + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/command_line.py b/command_line.py new file mode 100644 index 0000000..5a2cd21 --- /dev/null +++ b/command_line.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +import argparse + +# from md_tagebuch import __version__ +import converter + +def get_parser(): + parser = argparse.ArgumentParser(description='Generate marp markdown slides from csv') + # required arg + parser.add_argument("inputFile", help="name of the csv file to used as input, e.g. quiz.csv", + type=str) + return parser + + +def command_line_runner(): + parser = get_parser() + args = parser.parse_args() + converter.write_markdown_file(args.inputFile) + + +if __name__ == "__main__": + command_line_runner() diff --git a/converter.py b/converter.py index 0db85c9..744d21c 100644 --- a/converter.py +++ b/converter.py @@ -40,18 +40,21 @@ def write_markdown_file(csv_path): 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 = "" + # copy template template_name = "quiz-slides-template.md" shutil.copyfile(template_name, markdown_path) # with open(markdown_path, 'w', encoding='UTF-8') as markdown_file: + # append questions and answers to copy of template with open(markdown_path, 'a', encoding='UTF-8') as markdown_file: # write month headline - markdown_file.writelines(static_part) + # markdown_file.writelines(static_part) for q_and_a in list_of_q_and_as: print(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])) @@ -62,6 +65,7 @@ def write_markdown_file(csv_path): markdown_file.writelines('\n') markdown_file.writelines(' - {}'.format(q_and_a.answerArray[3])) markdown_file.writelines('\n') + markdown_file.writelines('---') markdown_file.close() # return filename