From 6039a3a4949397b3a01d87b949a32cd47117cea5 Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 31 Mar 2025 19:11:15 +0100 Subject: [PATCH] update cmd app --- docs/cmd.md | 6 ++++++ src/python/qubed/__main__.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/cmd.md b/docs/cmd.md index 40f9b51..240da66 100644 --- a/docs/cmd.md +++ b/docs/cmd.md @@ -23,8 +23,14 @@ There's some handy test data in the `tests/data` directory. For example: gzip -dc tests/data/fdb_list_compact.gz| qubed convert --from=fdb --to=text --output=qube.txt gzip -dc tests/data/fdb_list_porcelain.gz| qubed convert --from=fdb --to=json --output=qube.json gzip -dc tests/data/fdb_list_compact.gz | qubed convert --from=fdb --to=html --output=qube.html + +// Operational data stream=oper/wave/enfo/waef +fdb list class=od,expver=0001,date=0,stream=oper --compact >> operational_compact.txt +operational_compact.txt | qubed convert --from=fdb --to=text --output=operational.txt ``` + + ## Todo --from for diff --git a/src/python/qubed/__main__.py b/src/python/qubed/__main__.py index 9cceb53..ad4f6e4 100644 --- a/src/python/qubed/__main__.py +++ b/src/python/qubed/__main__.py @@ -1,3 +1,4 @@ +import json import time import click @@ -107,7 +108,15 @@ def convert(input, output, from_format, to_format): n0 = q.n_leaves t = time.time() - output_content = str(q) if to_format == "text" else q.html().html + if to_format == "text": + output_content = str(q) + elif to_format == "json": + output_content = json.dumps(q.to_json()) + elif to_format == "html": + output_content = q.html().html + else: + output_content = str(q) + output.write(output_content)