From a8f919b3867aabce4b6e7fd5f467c63746537d92 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 29 Dec 2022 22:47:59 +0200 Subject: [PATCH] Catch exception to skip invalid file --- src/stravavis/process_data.py | 6 +++- tests/gpx/invalid-lon-lat-missing.gpx | 42 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/gpx/invalid-lon-lat-missing.gpx diff --git a/src/stravavis/process_data.py b/src/stravavis/process_data.py index 700488a..e63be75 100644 --- a/src/stravavis/process_data.py +++ b/src/stravavis/process_data.py @@ -19,7 +19,11 @@ def process_file(fpath): # Ref: https://pypi.org/project/gpxpy/ def process_gpx(gpxfile): with open(gpxfile, encoding="utf-8") as f: - activity = gpxpy.parse(f) + try: + activity = gpxpy.parse(f) + except gpxpy.mod_gpx.GPXException as e: + print(f"\nSkipping {gpxfile}: {type(e).__name__}: {e}") + return None lon = [] lat = [] diff --git a/tests/gpx/invalid-lon-lat-missing.gpx b/tests/gpx/invalid-lon-lat-missing.gpx new file mode 100644 index 0000000..fe45715 --- /dev/null +++ b/tests/gpx/invalid-lon-lat-missing.gpx @@ -0,0 +1,42 @@ + + + + + GOTOES STRAVA TOOLS + + + + + Other + + + 31.2 + + + 0 + + + + 31.2 + + + 29 + + + + 31.2 + + + 29 + + + + 31.2 + + + 29 + + + + + \ No newline at end of file