From c1f1e2bb0e5bb2bb7e06f1e234b0b2316168a921 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 17 Mar 2022 15:25:05 +0100 Subject: [PATCH] added the possibility to redirect parsed data to stdout --- README.md | 4 +++- sensospot_data/__init__.py | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 991342f..e7a7467 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,9 @@ Arguments: SOURCE: Folder with Sensospot measurement Options: - -o, --outfile TEXT Output file name, relative to SOURCE, defaults to 'collected_data.csv' + -o, --outfile TEXT Output file name, use a dash '-' for stdout, default: + 'collected_data.csv' + -q, --quiet Ignore Sanity Check --help Show this message and exit. ``` diff --git a/sensospot_data/__init__.py b/sensospot_data/__init__.py index 9dad0a0..8990ed8 100644 --- a/sensospot_data/__init__.py +++ b/sensospot_data/__init__.py @@ -6,6 +6,7 @@ Parsing the numerical output from Sensovations Sensospot image analysis. __version__ = "0.6.0" +import sys from pathlib import Path import click @@ -29,7 +30,10 @@ from .parameters import ExposureInfo # noqa: F401 "-o", "--outfile", default="collected_data.csv", - help="Output file name", + help=( + "Output file name, use a dash '-' for stdout, " + "default: 'collected_data.csv'" + ), ) @click.option( "-q", @@ -42,5 +46,8 @@ def run(source, outfile, quiet=False): source_path = Path(source) # read the raw data of a folder raw_data = parse_folder(source_path, quiet=quiet) - csv_file = source_path / outfile - raw_data.to_csv(csv_file, sep="\t") + if outfile.strip() == "-": + raw_data.to_csv(sys.stdout, sep="\t") + else: + csv_file = source_path / outfile + raw_data.to_csv(csv_file, sep="\t")