-
-
Save lantrix/1295169 to your computer and use it in GitHub Desktop.
Simple script to convert HRM data from XML documents exported via http://www.personaltrainer.com (e.g. for use with RunKeeper)
This file contains hidden or 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 'rexml/document' | |
def file_name(file) | |
if file.end_with?(".xml") then | |
file = file.gsub(".xml", ".hrm") | |
else | |
file = "#{file}.hrm" | |
end | |
return file | |
end | |
if ARGV.count == 1 then | |
file = ARGV.first | |
if File.exists?(file) then | |
xmlfile = File.open(file, 'rb') | |
xmldoc = REXML::Document.new(xmlfile.read) | |
hrmdata = xmldoc.elements['polar-exercise-data/calendar-items/exercise/result/samples/sample/values'].get_text | |
open(file_name(file), 'w') { |f| | |
f << "[Params]\nInterval=5\n[HRData]\n" | |
"#{hrmdata}".split(',').each do |v| | |
f << "#{v}\n" | |
end | |
} | |
else | |
puts "Could not find #{ARGV.first}" | |
end | |
else | |
puts "Usage: 'ruby xml2hrm polarpersonaltrainer.xml'" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment