Skip to content

Instantly share code, notes, and snippets.

@braxtone
Created October 23, 2015 05:19
Show Gist options
  • Save braxtone/c290154794a90e93482d to your computer and use it in GitHub Desktop.
Save braxtone/c290154794a90e93482d to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Parses the XML format that iOS' HealthKit export feature creates, extracting step counts and dumping out a CSV
require 'nokogiri'
require 'date'
filename = ARGV[0]
def process_date(date)
DateTime.parse(date).strftime('%Y-%m-%d %H:%M:%S')
end
xml = Nokogiri::XML(File.open(filename))
puts %w( type source unit startDate endDate value recordCount).join(',')
xml.xpath("//Record[@type='HKQuantityTypeIdentifierStepCount']").each do |record|
ret = [
record['type'],
record['source'],
record['unit'],
process_date(record['startDate']),
process_date(record['endDate']),
record['value'],
record['recordCount']
]
puts ret.join(',')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment