enumerate questions with alphabet, convert md to pdf with docker sdk
This commit is contained in:
		
							
								
								
									
										22
									
								
								converter.py
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								converter.py
									
									
									
									
									
								
							| @@ -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()) | ||||
|   | ||||
| @@ -0,0 +1,8 @@ | ||||
| certifi==2021.5.30 | ||||
| chardet==4.0.0 | ||||
| docker==5.0.0 | ||||
| idna==2.10 | ||||
| pywin32==227 | ||||
| requests==2.25.1 | ||||
| urllib3==1.26.5 | ||||
| websocket-client==1.1.0 | ||||
|   | ||||
							
								
								
									
										8
									
								
								tests.py
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								tests.py
									
									
									
									
									
								
							| @@ -24,6 +24,14 @@ class TestDiary(unittest.TestCase): | ||||
|         # assert file was created | ||||
|         assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md"))) | ||||
|  | ||||
|     def test_to_pdf(self): | ||||
|         # python command_line 2021-01 | ||||
|         BASE_FODLER = "test_data" | ||||
|         converter.to_pdf("slide-deck.md") | ||||
|  | ||||
|         # 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" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user