From 31b907900cf5d984c3c15d708e55d33c9c124ce2 Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 21 Nov 2023 09:20:33 +0200 Subject: [PATCH] feat(cli): added output format "text" --- newspaper/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/newspaper/cli.py b/newspaper/cli.py index 94f385a..3d955c0 100644 --- a/newspaper/cli.py +++ b/newspaper/cli.py @@ -46,7 +46,7 @@ def get_arparse() -> argparse.ArgumentParser: parser.add_argument( "--output-format", "-of", - choices=["csv", "json"], + choices=["csv", "json", "text"], default="json", help="The output format of the parsed article.", ) @@ -228,6 +228,9 @@ def csv_string(article_dict: dict) -> str: if idx == 0: write_output(csv_header()) write_output(csv_string(output)) + elif args.output_format == "text": + write_output(f"{article.title}\n\n") + write_output(article.text) else: raise ValueError(f"Unknown output format: {args.output_format}")