Skip to content

Instantly share code, notes, and snippets.

@chantra
Created December 4, 2019 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chantra/e1c2ca4cbb1934a1fb322dbd770fffdf to your computer and use it in GitHub Desktop.
Save chantra/e1c2ca4cbb1934a1fb322dbd770fffdf to your computer and use it in GitHub Desktop.
#!/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