Created
September 20, 2011 06:29
-
-
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)
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
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
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?