add command line interface
This commit is contained in:
parent
7ec4a56d53
commit
ec4135035d
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
.idea
|
||||
csvmarp
|
||||
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
23
command_line.py
Normal file
23
command_line.py
Normal file
@ -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()
|
10
converter.py
10
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user