Last active
December 3, 2022 12:38
-
-
Save dlo/fa537daf94cb3bb5527bc86ea10dced0 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/env python | |
import json | |
import datetime | |
def date_from_row(row): | |
year = row['year'] | |
month = row['month'] | |
day = row['day'] | |
hour = row['hour'] | |
minute = row['minute'] | |
return datetime.datetime(year, month, day, hour, minute).isoformat() | |
with open("sampleData.py") as f: | |
rows = json.load(f) | |
print """<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE HealthData [ | |
<!-- HealthKit Export Version: 3 --> | |
<!ELEMENT HealthData (ExportDate,Me,(Record|Correlation|Workout|ActivitySummary)*)> | |
<!ATTLIST HealthData | |
locale CDATA #REQUIRED | |
> | |
<!ELEMENT ExportDate EMPTY> | |
<!ATTLIST ExportDate | |
value CDATA #REQUIRED | |
> | |
<!ELEMENT Me EMPTY> | |
<!ATTLIST Me | |
HKCharacteristicTypeIdentifierDateOfBirth CDATA #REQUIRED | |
HKCharacteristicTypeIdentifierBiologicalSex CDATA #REQUIRED | |
HKCharacteristicTypeIdentifierBloodType CDATA #REQUIRED | |
HKCharacteristicTypeIdentifierFitzpatrickSkinType CDATA #REQUIRED | |
> | |
<!ELEMENT Record (MetadataEntry*)> | |
<!ATTLIST Record | |
type CDATA #REQUIRED | |
unit CDATA #IMPLIED | |
value CDATA #IMPLIED | |
sourceName CDATA #REQUIRED | |
sourceVersion CDATA #IMPLIED | |
device CDATA #IMPLIED | |
creationDate CDATA #IMPLIED | |
startDate CDATA #REQUIRED | |
endDate CDATA #REQUIRED | |
> | |
<!-- Note: Any Records that appear as children of a correlation also appear as top-level records in this document. --> | |
<!ELEMENT Correlation ((MetadataEntry|Record)*)> | |
<!ATTLIST Correlation | |
type CDATA #REQUIRED | |
sourceName CDATA #REQUIRED | |
sourceVersion CDATA #IMPLIED | |
device CDATA #IMPLIED | |
creationDate CDATA #IMPLIED | |
startDate CDATA #REQUIRED | |
endDate CDATA #REQUIRED | |
> | |
<!ELEMENT Workout ((MetadataEntry|WorkoutEvent)*)> | |
<!ATTLIST Workout | |
workoutActivityType CDATA #REQUIRED | |
duration CDATA #IMPLIED | |
durationUnit CDATA #IMPLIED | |
totalDistance CDATA #IMPLIED | |
totalDistanceUnit CDATA #IMPLIED | |
totalEnergyBurned CDATA #IMPLIED | |
totalEnergyBurnedUnit CDATA #IMPLIED | |
sourceName CDATA #REQUIRED | |
sourceVersion CDATA #IMPLIED | |
device CDATA #IMPLIED | |
creationDate CDATA #IMPLIED | |
startDate CDATA #REQUIRED | |
endDate CDATA #REQUIRED | |
> | |
<!ELEMENT WorkoutEvent EMPTY> | |
<!ATTLIST WorkoutEvent | |
type CDATA #REQUIRED | |
date CDATA #REQUIRED | |
> | |
<!ELEMENT ActivitySummary EMPTY> | |
<!ATTLIST ActivitySummary | |
dateComponents CDATA #IMPLIED | |
activeEnergyBurned CDATA #IMPLIED | |
activeEnergyBurnedGoal CDATA #IMPLIED | |
activeEnergyBurnedUnit CDATA #IMPLIED | |
appleExerciseTime CDATA #IMPLIED | |
appleExerciseTimeGoal CDATA #IMPLIED | |
appleStandHours CDATA #IMPLIED | |
appleStandHoursGoal CDATA #IMPLIED | |
> | |
<!ELEMENT MetadataEntry EMPTY> | |
<!ATTLIST MetadataEntry | |
key CDATA #REQUIRED | |
value CDATA #REQUIRED | |
> | |
]> | |
<HealthData locale="en_US"> | |
""" | |
for row in rows: | |
date = date_from_row(row) | |
row['creationDate'] = date | |
row['startDate'] = date | |
row['endDate'] = date | |
# Type identifiers available from https://developer.apple.com/reference/healthkit/healthkit_constants?language=objc#2315149 | |
# Provide `unit` as a string (e.g., "mi") | |
# Other record types, such as workouts, are more complex and have some undocumented requirements. | |
print """<Record type="HKQuantityTypeIdentifierBloodGlucose" sourceName="Python Script" sourceVersion="1.0" unit="mg/dL" creationDate="{creationDate}" startDate="{startDate}" endDate="{endDate}" value="{value}">""".format(**row) | |
print "</HealthData>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I quite suspicious that the health report on this item can be abuse from health condition according to form identified to something else for instance, someone information, banking numbers, concept and idea of someone, betrayal thought and deception against someone loyalty. Please analyze the health report that attached with this comment. Thank you.)




