applehealth

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2021 License: MIT Imports: 9 Imported by: 2

README

applehealth

PkgGoDev Go Report Card

Go module for accessing Apple Health exported data.

You can export your health data on the iPhone by launching the Health app, tapping your photo in the top right corner, and tapping "Export All Health Data" below. If you have a lot of data, the export will take a lot of time, and the app can be unresponsive.

See API documentation for examples.

Documentation

Overview

Package applehealth provides access to Apple Health exported data.

Example
file := filepath.Join("testdata", "testdata.zip")
u, err := NewUnmarshaler(file)
if err != nil {
	log.Fatal(err)
}
defer u.Close()

// call Next() once to be able to read metadata
var data healthkit.Data
if data, err = u.Next(); err != nil {
	log.Fatal(err)
}

fmt.Printf("Meta: %s\n", u.Meta())

for {
	fmt.Printf("Got %T:\n", data)
	switch data := data.(type) {
	case *healthkit.Record:
		fmt.Printf("\t%s\n", data.Type)
	}

	if data, err = u.Next(); err != nil {
		break
	}
}
if err != io.EOF {
	log.Fatal(err)
}
Output:

Meta: {Locale:ru_RU ExportDate:{XMLName:{Space: Local:ExportDate} Value:2019-12-26 08:20:53 +0300} Me:{XMLName:{Space: Local:Me} DateOfBirth:1987-10-02 BiologicalSex:HKBiologicalSexFemale BloodType:HKBloodTypeABPositive FitzpatrickSkinType:HKFitzpatrickSkinTypeVI}}
Got *healthkit.Record:
	HKQuantityTypeIdentifierHeight
Got *healthkit.Record:
	HKQuantityTypeIdentifierBodyMass

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser struct {
	DisallowUnhandledElements bool // if true, Next() will return UnhandledElementError for unhandled data
	// contains filtered or unexported fields
}

Parser is responsible for parsing Apple Health XML stream.

Most users should use Unmarshaler instead.

func NewParser

func NewParser(d *xml.Decoder) *Parser

NewParser creates a new parser with given XML decoder.

Most users should use NewUnmarshaler instead.

func (*Parser) InputOffset

func (p *Parser) InputOffset() int64

InputOffset returns XML stream input offset. Unlike calling xml.Decoder.InputOffset directly, that method can be called concurrently with Next().

func (*Parser) Meta

func (p *Parser) Meta() *healthkit.Meta

Meta returns parsed metadata after the first call to Next().

func (*Parser) Next

func (p *Parser) Next() (healthkit.Data, error)

Next returns the next health data object, or error (io.EOF, *UnhandledElementError, or XML parsing error).

type Stats

type Stats struct {
	Pos  int64
	Size int64
}

Stats represent Unmarshaler's statistics.

type UnhandledElementError

type UnhandledElementError struct {
	Name string
}

UnhandledElementError is returned by the Parser from the Next() method if DisallowUnhandledElements is true and unhandled data is encountered.

func (*UnhandledElementError) Error

func (u *UnhandledElementError) Error() string

type Unmarshaler

type Unmarshaler struct {
	*Parser
	// contains filtered or unexported fields
}

Unmarshaler is responsible for parsing Apple Health exported ZIP or XML files.

It embeds Parser as a public field, so Parser's exported methods like Next() and Meta() can be called directly.

func NewUnmarshaler

func NewUnmarshaler(file string) (*Unmarshaler, error)

NewUnmarshaler creates a new Unmarshaler for a given ZIP or XML file.

func (*Unmarshaler) Close

func (p *Unmarshaler) Close() error

Close closes the file.

func (*Unmarshaler) Stats

func (p *Unmarshaler) Stats() Stats

Stats return the current Unmarshaler's statistics.

Directories

Path Synopsis
Package healthkit contains Apple's HealthKit types and constants.
Package healthkit contains Apple's HealthKit types and constants.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL