hevslib.applehealth module

applehealth.py: Extract data from Apple Health App’s export.xml.

class hevslib.applehealth.HealthDataExtractor(path, verbose=True)

Bases: object

Extract health data from Apple Health App’s XML export, export.xml.

Inputs:

path: Relative or absolute path to export.xml verbose: Set to False for less verbose output

Outputs:

Writes a CSV file for each record type found, in the same directory as the input export.xml. Reports each file written unless verbose has been set to False.

abbreviate_types()

Shorten types by removing common boilerplate text.

close_files()
collect_stats()
count_record_types()

Counts occurrences of each type of (conceptual) “record” in the data. In the case of nodes of type ‘Record’, this counts the number of occurrences of each ‘type’ or record in self.record_types. In the case of nodes of type ‘ActivitySummary’ and ‘Workout’, it just counts those in self.other_types. The slightly different handling reflects the fact that ‘Record’ nodes come in a variety of different subtypes that we want to write to different data files, whereas (for now) we are going to write all Workout entries to a single file, and all ActivitySummary entries to another single file.

count_tags_and_fields()
extract()
open_for_writing()
report(msg, end='\n')
report_stats()
write_records()
hevslib.applehealth.abbreviate(s, enabled=True)

Abbreviate particularly verbose strings based on a regular expression

hevslib.applehealth.encode(s)

Encode string for writing to file. In Python 2, this encodes as UTF-8, whereas in Python 3, it does nothing

hevslib.applehealth.format_freqs(counter)

Format a counter object for display.

hevslib.applehealth.format_value(value, datatype)

Format a value for a CSV file, escaping double quotes and backslashes. None maps to empty. datatype should be * ‘s’ for string (escaped) * ‘n’ for number * ‘d’ for datetime