From 89806e0be284ad7dde5f5845f39c28c943642555 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Tue, 13 Oct 2020 22:47:11 +0200 Subject: [PATCH] move the main decision tree to __main__ --- url2markdown/__main__.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/url2markdown/__main__.py b/url2markdown/__main__.py index 7b90274..7e9f0dd 100755 --- a/url2markdown/__main__.py +++ b/url2markdown/__main__.py @@ -5,12 +5,22 @@ from url2markdown.file import write_to_file from url2markdown.header import Header -def main(): - args = cli() - article = downloader(args.URL) - header = Header(article, args.topics) +def main(url, topics): + article = downloader(url) + header = Header(article, topics) write_to_file(article, header.build_header()) if __name__ == "__main__": - main() + args = cli() + if args.url: + main(args.url, args.topics) + if args.file: + with args.file as input_file: + for line in input_file: + try: + url, topics = line.split(' ') + except ValueError: + url = line + topics = [] + main(url, topics)