{"id":1362,"date":"2023-09-01T16:06:56","date_gmt":"2023-09-01T21:06:56","guid":{"rendered":"https:\/\/www.nathanhunstad.com\/blog\/?p=1362"},"modified":"2023-09-01T16:06:57","modified_gmt":"2023-09-01T21:06:57","slug":"parsefit-my-simple-python-tool-to-parse-tcx-files-from-google-fit","status":"publish","type":"post","link":"https:\/\/www.nathanhunstad.com\/blog\/2023\/09\/parsefit-my-simple-python-tool-to-parse-tcx-files-from-google-fit\/","title":{"rendered":"ParseFit: My simple Python tool to parse TCX files from Google Fit"},"content":{"rendered":"\n<p>Over ten years ago, I used a tool called SportyPal to track my bike rides on my <a href=\"https:\/\/www.nathanhunstad.com\/blog\/2010\/04\/another-smartphone-convert\/\" target=\"_blank\" rel=\"noopener\" title=\"\">fancy new smartphone<\/a>. 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.<\/p>\n\n\n\n<p>This wasn&#8217;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&#8217;t want this to happen again.<\/p>\n\n\n\n<p>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 <a href=\"https:\/\/www.nathanhunstad.com\/blog\/2023\/08\/add-geolocation-data-to-photos-the-easy-way\/\" target=\"_blank\" rel=\"noopener\" title=\"\">post about Geosetter<\/a>. 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?<\/p>\n\n\n\n<p>One thing I wanted to do was ensure that I could keep track of things like distance outside of Google Fit, which isn&#8217;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 <a href=\"https:\/\/github.com\/huns0004\/ParseFit\" target=\"_blank\" rel=\"noopener\" title=\"\">ParseFit<\/a> was born.<\/p>\n\n\n\n<p>It&#8217;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 &#8220;Biking&#8221; or &#8220;Walking&#8221;, and you&#8217;ll get distance data in text or CSV format per workout:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">File: 2023-06-25T10_14_03.336-05_00_PT1H26M30.682S_Biking.tcx, NiceDate: 06\/25\/2023, Distance: 29748.637312993083\r\nFile: 2023-07-02T08_09_08.331-05_00_PT2H16M57.505S_Biking.tcx, NiceDate: 07\/02\/2023, Distance: 43849.77351833329\r\nFile: 2023-07-23T10_10_47.441-05_00_PT1H58M50.898S_Biking.tcx, NiceDate: 07\/23\/2023, Distance: 35872.04551453308<\/pre>\n\n\n\n<p>As an aside, I used ChatGPT to generate some of this code, but as I&#8217;ve found with using AI for code, it&#8217;s only a start: you have to know the language well enough to take what AI gives you and expand upon it. So it&#8217;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.<\/p>\n\n\n\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After losing all my workout data when SportyPal disappeared, I wrote a tool in Python to parse TCX files from Google Fit so it doesn&#8217;t happen again.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1362","post","type-post","status-publish","format-standard","hentry","category-tech-2","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/posts\/1362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/comments?post=1362"}],"version-history":[{"count":3,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/posts\/1362\/revisions"}],"predecessor-version":[{"id":1366,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/posts\/1362\/revisions\/1366"}],"wp:attachment":[{"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/media?parent=1362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/categories?post=1362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/tags?post=1362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}