Created
April 28, 2012 14:59
-
-
Save HerbCSO/2519671 to your computer and use it in GitHub Desktop.
Parse Garmin TCX file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'nokogiri' | |
xml=Nokogiri::XML File.open 'My Activities_history.tcx' | |
xml.remove_namespaces! | |
$stdout.reopen("activities.csv", "w") | |
$stdout.sync = true | |
$stderr.reopen($stdout) | |
puts '"Sport","Id","LapStartTime","TotalTimeSeconds","DistanceMeters","MaximumSpeed","Calories","AverageHeartRateBpm","MaximumHeartRateBpm"' | |
xml.xpath("//Activity").each do |activity| | |
activity.xpath('Lap').each do |lap| | |
puts "\"#{ activity['Sport'] }\","\ | |
"\"#{ activity.xpath('Id').children }\","\ | |
"\"#{ lap['StartTime'] }\","\ | |
"#{ lap.xpath('TotalTimeSeconds').children },"\ | |
"#{ lap.xpath('DistanceMeters').children },"\ | |
"#{ lap.xpath('MaximumSpeed').children },"\ | |
"#{ lap.xpath('Calories').children },"\ | |
"#{ lap.xpath('AverageHeartRateBpm/Value').children },"\ | |
"#{ lap.xpath('MaximumHeartRateBpm/Value').children }"\ | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment