Skip to content

Commit

Permalink
Merge pull request marcusvolz#43 from hugovk/exit-zero-filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Feb 9, 2024
2 parents a38449e + 4baf655 commit 3f05e06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/stravavis/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import argparse
import glob
import os.path
import sys


def main():
Expand Down Expand Up @@ -87,6 +89,10 @@ def main():
if os.path.isdir(args.path):
args.path = os.path.join(args.path, "*")

filenames = glob.glob(args.path)
if not filenames:
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 = (
Expand All @@ -108,7 +114,7 @@ def main():
from .process_data import process_data

print("Processing data...")
df = process_data(args.path)
df = process_data(filenames)

activities = None
if args.activities_path:
Expand Down
7 changes: 3 additions & 4 deletions src/stravavis/process_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import glob
from __future__ import annotations

import math
from multiprocessing import Pool

Expand Down Expand Up @@ -101,10 +102,8 @@ def process_fit(fitfile):


# Function for processing (unzipped) GPX and FIT files in a directory (path)
def process_data(path):
def process_data(filenames: list[str]) -> pd.DataFrame:
# Process all files (GPX or FIT)
filenames = glob.glob(path)

with Pool() as pool:
try:
it = pool.imap_unordered(process_file, filenames)
Expand Down

0 comments on commit 3f05e06

Please sign in to comment.