Skip to content

Instantly share code, notes, and snippets.

@nst
Created August 13, 2016 13:48
Show Gist options
  • Save nst/36d67069618cfec5e89127710a249392 to your computer and use it in GitHub Desktop.
Save nst/36d67069618cfec5e89127710a249392 to your computer and use it in GitHub Desktop.
Fix GPX paths exported from Strava by restoring the timestamp
#!/usr/bin/env python
"""
For some reason, Strava lets you export the GPX of another athletes but removes
the timestamps, presumably so that you can't "steal" their paths.
This script adds fake timestamps to these GPX files, so that you see the
overview of the run in other services like doarama for instance.
Technically, the script adds a timstamp after the </ele> tag, +1s at each point:
</ele>
<time>2016-01-01T00:00:31</time>
Nicolas Seriot
2016-07-04
"""
import datetime
with open("/Users/nst/Desktop/x.gpx") as f:
i = 0
for l in f:
dt = datetime.datetime(2016, 1, 1) + datetime.timedelta(seconds=i)
s = l.replace("</ele>", "</ele>\n <time>" + dt.isoformat() + "</time>")
if s != l:
i += 1
print(s),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment