From 1ee677586ebe929d88c7ba5575b58053c928fdde Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Mon, 18 Mar 2024 04:36:43 +0100 Subject: convert.py: add output-file argument. Signed-off-by: Denis 'GNUtoo' Carikli --- Makefile | 1 - convert.py | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index f13298c..88cecc9 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,6 @@ markdown: html sed 's#https://blog.replicant.us/##' | \ sed 's#/$$##'| \ sed 's#/#_#g'`.html \ - > \ markdown/`echo "$${url}" | \ sed 's#https://blog.replicant.us/##' | \ sed 's#/$$##'| \ diff --git a/convert.py b/convert.py index 6c72bab..03c6965 100755 --- a/convert.py +++ b/convert.py @@ -25,7 +25,7 @@ import sh import sys def usage(progname): - print("Usage:\n\t{} ".format(progname)) + print("Usage:\n\t{} ".format(progname)) # A "[1]" in the html becomes "[[1]][6]" in text. # As we already uses references at the end a [6] would @@ -238,16 +238,21 @@ def get_metadata(html_file_path): return metadata def main(): - if len(sys.argv) != 2: + if len(sys.argv) != 3: usage(sys.argv[0]) sys.exit(os.EX_USAGE) - html_file_path = sys.argv[1] + input_html_file_path = sys.argv[1] + output_markdown_file_path = sys.argv[2] - text = get_metadata(html_file_path) - text += convert(html_file_path) + text = get_metadata(input_html_file_path) + text += convert(input_html_file_path) - sys.stdout.write(text) + if output_markdown_file_path == '-': + sys.stdout.write(text) + else: + with open(output_markdown_file_path, 'w') as markdown_file: + markdown_file.write(text) if __name__ == '__main__': main() -- cgit v1.2.3