diff --git a/scripts/export_for_fabledcurator.py b/scripts/export_for_fabledcurator.py index 0043aa0..a59ea96 100644 --- a/scripts/export_for_fabledcurator.py +++ b/scripts/export_for_fabledcurator.py @@ -114,6 +114,16 @@ def _export_series_pages(): def main() -> None: + import argparse + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--output", + default=None, + help="Write JSON to this path instead of stdout (use this when " + "running inside a Swarm service that writes to a bind-mount).", + ) + args = parser.parse_args() + app = create_app() with app.app_context(): export = { @@ -125,8 +135,18 @@ def main() -> None: "image_tag_associations": _export_image_tag_associations(), "series_pages": _export_series_pages(), } - json.dump(export, sys.stdout, indent=2) - sys.stdout.write("\n") + + if args.output: + from pathlib import Path + out_path = Path(args.output) + out_path.parent.mkdir(parents=True, exist_ok=True) + out_path.write_text(json.dumps(export, indent=2) + "\n") + print(f"wrote {out_path} ({len(export['tags'])} tags, " + f"{len(export['image_tag_associations'])} associations)", + file=sys.stderr) + else: + json.dump(export, sys.stdout, indent=2) + sys.stdout.write("\n") if __name__ == "__main__":