Skip to content

Commit

Permalink
Merge pull request #27 from hugovk/skip-invalid-file
Browse files Browse the repository at this point in the history
Fixes #23
  • Loading branch information
hugovk authored Dec 30, 2022
2 parents 13e67f7 + a8f919b commit 71d6d16
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
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>

0 comments on commit 71d6d16

Please sign in to comment.