Skip to content

Instantly share code, notes, and snippets.

@mgratzer
Created September 20, 2011 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mgratzer/1228496 to your computer and use it in GitHub Desktop.
Save mgratzer/1228496 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)
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
@GeertClaes
Copy link

Is this still working? Do you have a demo site somewhere where you can test a file? I tried http://www.mgratzer.com/web-based-polar-personal-trainer-xml-to-hrm-converter/ but when I click "Get HRM file" it returns to "No file chosen". I can upload a file to your DBInbox if you like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment