If you've ever wanted to analyze your own health data, here's how.
Within the archive, you'll find
export.xml. This is where the main metrics are stored.
If you open
export.xml, you'll see most of the interesting data is contained in the attributes of
Record elements. So let's make a small Python script to convert those attributes into JSON.
Save the following in a file called
import json import sys from xml.etree.ElementTree import iterparse for _, elem in iterparse(sys.argv): if elem.tag == "Record": print(json.dumps(elem.attrib))
python parse.py export.xml
You should immediately start seeing the data in your terminal.
jq, we can easily turn the JSON into CSV:
python parse.py export.xml | jq -r '[.endDate, .type, .unit, .value] | @csv'
If you prefer TSV (e.g. for processing with
Save the data to a file and analyze with your favorite software.