From 4dfa08bbbc119ba1d8a62a52311bcd2829909024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=B6ttel?= <1682504+fspoettel@users.noreply.github.com> Date: Fri, 1 Jul 2022 17:08:53 +0200 Subject: [PATCH] feat: add `--open` flag (#11) closes #5 --- README.md | 2 ++ geoclustering/__main__.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 745a2b6..c646caa 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ Options: Clustering algorithm to be used. `optics` produces tighter clusters but is slower. Default: dbscan + --open Open the generated visualization in the + default browser automatically. --help Show this message and exit. ``` diff --git a/geoclustering/__main__.py b/geoclustering/__main__.py index d67846f..a2b71d5 100644 --- a/geoclustering/__main__.py +++ b/geoclustering/__main__.py @@ -38,8 +38,13 @@ import geoclustering.io as io default="dbscan", help="Clustering algorithm to be used. `optics` produces tighter clusters but is slower. Default: dbscan", ) +@click.option( + "--open", + is_flag=True, + help="Open the generated visualization in the default browser automatically.", +) @click.argument("filename", type=click.Path(exists=True)) -def main(distance, size, output, filename, algorithm): +def main(distance, size, output, filename, algorithm, open): df = io.read_csv_file(filename) clusters = clustering.cluster_locations( @@ -57,7 +62,8 @@ def main(distance, size, output, filename, algorithm): io.write_output_file(output, "result.geojson", encoded["geojson"]) vis = io.write_visualization(output, "result.html", encoded["geojson"]) - webbrowser.open_new_tab("file://" + str(vis.absolute())) + if open: + webbrowser.open_new_tab("file://" + str(vis.absolute())) if __name__ == "__main__":