Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch exception to skip invalid file #27

Merged
merged 1 commit into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/stravavis/process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
42 changes: 42 additions & 0 deletions tests/gpx/invalid-lon-lat-missing.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" creator="Wahoo ELEMNT BOLT" version="5.8">
<metadata>
<link href="https://gotoes.org/strava/Combine_GPX_TCX_FIT_Files.php">
<text>GOTOES STRAVA TOOLS</text>
</link>
<time>2019-08-31T09:02:36Z</time>
</metadata>
<trk>
<type>Other</type>
<trkseg>
<trkpt>
<ele>31.2</ele>
<time>2019-08-31T09:02:36Z</time>
<extensions>
<gpxdata:temp>0</gpxdata:temp>
</extensions>
</trkpt>
<trkpt lon="24.12345" lat="60.12345">
<ele>31.2</ele>
<time>2019-08-31T09:02:37Z</time>
<extensions>
<gpxdata:temp>29</gpxdata:temp>
</extensions>
</trkpt>
<trkpt lon="24.12345" lat="60.12345">
<ele>31.2</ele>
<time>2019-08-31T09:02:38Z</time>
<extensions>
<gpxdata:temp>29</gpxdata:temp>
</extensions>
</trkpt>
<trkpt lon="24.12345" lat="60.12345">
<ele>31.2</ele>
<time>2019-08-31T09:02:39Z</time>
<extensions>
<gpxdata:temp>29</gpxdata:temp>
</extensions>
</trkpt>
</trkseg>
</trk>
</gpx>