From af8616a5d44374a25a080a81e0f44818f42dfc12 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 20 Oct 2024 16:39:01 +0300 Subject: [PATCH] Allow --bbox to be a file containing four bounding-box coordinates --- .gitignore | 7 +++++++ README.md | 30 ++++++++++++++++++++++++++++++ src/stravavis/cli.py | 17 +++++++++++++---- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 73fd16e..b55bcf9 100644 --- a/.gitignore +++ b/.gitignore @@ -128,5 +128,12 @@ dmypy.json # Pyre type checker .pyre/ +# Strava data +activities.csv +activities/ + +# Arbitrary extension for bounding box coordinates +*.bbox + # Generated files *.png diff --git a/README.md b/README.md index d58902c..eab83f4 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,36 @@ Then run from the terminal: stravavis --help ``` +## How to use + +If your activity data is in a folder called `activities`, run the following command: + +```sh +stravavis activities +``` + +By default, this will create output images prefixed `strava-`. + +If you have an `activities.csv` file: + +```sh +stravavis activities --activities_path activities.csv +``` + +To only map activities contained within a +[bounding box](https://boundingbox.klokantech.com/): + +```sh +stravavis activities --bbox 24.782802,59.922486,25.254511,60.29785` +``` + +Or as a shortcut, save bounding-box coordinates to a file: + +```sh +echo 24.782802,59.922486,25.254511,60.29785 > helsinki.bbox +stravavis activities --bbox helsinki.bbox +``` + ## Examples ### Facets diff --git a/src/stravavis/cli.py b/src/stravavis/cli.py index 76f8139..39f1ff1 100644 --- a/src/stravavis/cli.py +++ b/src/stravavis/cli.py @@ -96,10 +96,19 @@ def main(): sys.exit(f"No files found matching {args.path}") if args.bbox: - # Convert comma-separated string into floats - args.lon_min, args.lat_min, args.lon_max, args.lat_max = ( - float(x) for x in args.bbox.split(",") - ) + try: + bbox_values = args.bbox.split(",") + if len(bbox_values) == 1: + with open(args.bbox) as f: + bbox_values = f.readline().split(",") + args.lon_min, args.lat_min, args.lon_max, args.lat_max = map( + float, bbox_values + ) + except ValueError: + sys.exit( + f"Bounding box '{args.bbox}' must be four comma-separated coordinates " + "or a file containing them" + ) if args.activities_path and os.path.isdir(args.activities_path): args.activities_path = os.path.join(args.activities_path, "activities.csv")