Created
October 23, 2015 05:19
-
-
Save braxtone/c290154794a90e93482d to your computer and use it in GitHub Desktop.
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/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