ParseFit: My simple Python tool to parse TCX files from Google Fit

Over ten years ago, I used a tool called SportyPal to track my bike rides on my fancy new smartphone. I used it for several years, then life intervened in the form of a house, kids, and a lot less time to bike. I forgot about the app for a while, and when I finally went back to it, I was in for a surprise: SportyPal was no more, and with no warning. Just like that, all of my data was gone, never to be seen again.

This wasn’t the first time that the death of a free service left me high and dry. For example, I and a lot of other people were very unhappy when Google dropped support for Google Reader. As a data hoarder it annoyed me to no end that all of this data was sent into a blackhole, and I didn’t want this to happen again.

Fast-forward to today. Nowadays I use Google Fit for tracking my workouts. This has two benefits: first, Google is unlikely to disappear anytime soon without warning, and second, they make it easy to download data as I talked about in my post about Geosetter. So I can, and have, downloaded my data just in case, and I have my activities safely stored in TCX files for long-term storage. But could I do better?

One thing I wanted to do was ensure that I could keep track of things like distance outside of Google Fit, which isn’t great at doing that kind of aggregate reporting. Distance is stored in those files, but in annoying and hard-to-use XML. Thus, I decided to create a Python script to parse out useful data, and ParseFit was born.

It’s nothing fancy: point it at a folder with TCX files in it, add an optional filter to only get data from some activities like “Biking” or “Walking”, and you’ll get distance data in text or CSV format per workout:

File: 2023-06-25T10_14_03.336-05_00_PT1H26M30.682S_Biking.tcx, NiceDate: 06/25/2023, Distance: 29748.637312993083
File: 2023-07-02T08_09_08.331-05_00_PT2H16M57.505S_Biking.tcx, NiceDate: 07/02/2023, Distance: 43849.77351833329
File: 2023-07-23T10_10_47.441-05_00_PT1H58M50.898S_Biking.tcx, NiceDate: 07/23/2023, Distance: 35872.04551453308

As an aside, I used ChatGPT to generate some of this code, but as I’ve found with using AI for code, it’s only a start: you have to know the language well enough to take what AI gives you and expand upon it. So it’s great for creating stub CSV or XML parsing output functions with Python syntax, for example, but you need to use your own brain to make it do what you want.

With this tool, I can better track my workouts outside of Google Fit and ensure my data is where I want it to be. When it comes to SaaS tools, especially free ones, you always need to work to preserve your data.

Leave a comment

Your email address will not be published. Required fields are marked *