Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
# Convert a TCX file exported from strava's export data:
# https://www.strava.com/activities/<activity_id>/export_original
# to a TCX file ready to upload to https://connect.garmin.com/
# This is based on the logic from http://rodemybike.today/strava-to-garmin/
# but I just find it more convenient to:
# ~/strava2garmin.py < strava_activity.tcx > garmin_activity.tcx
# or
# cat strava_activity.tcx | ~/strava2garmin.py > garmin_activity.tcx
import re
import sys
substitutions = [
('<Creator><Name>PELOTON</Name></Creator>', ''),
('\.\d+</Watts>', '</Watts>'),
('\.\d+</Calories>', '</Calories>'),
('\.\d+</Cadence>', '</Cadence>'),
('\.\d+</Value></AverageHeartRateBpm>', '</Value></AverageHeartRateBpm>'),
('\.\d+</Value></MaximumHeartRateBpm>', '</Value></MaximumHeartRateBpm>'),
('\.\d+</Value><HeartRateBpm>', '</Value></HeartRateBpm>'),
('\.0\<\/', '</'),
]
def main():
c = sys.stdin.read()
for orig, replacement in substitutions:
c = re.sub(orig, replacement, c, flags=re.IGNORECASE )
print(c)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.