Skip to content

Instantly share code, notes, and snippets.

@lantrix
Forked from mgratzer/pptxml2hrm.rb
Created October 18, 2011 11:04
Show Gist options
  • Save lantrix/1295169 to your computer and use it in GitHub Desktop.
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)
#!/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