From 455eda9ed1b345014782658e22330165e8b50185 Mon Sep 17 00:00:00 2001 From: Nathan Henrie Date: Sat, 13 Mar 2021 06:35:06 -0700 Subject: [PATCH] Add a fallback ID, print if no ID found --- healthkit_to_sqlite/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/healthkit_to_sqlite/utils.py b/healthkit_to_sqlite/utils.py index fea6bc7..c43246c 100644 --- a/healthkit_to_sqlite/utils.py +++ b/healthkit_to_sqlite/utils.py @@ -54,7 +54,16 @@ def workout_to_db(workout, db, zipfile=None): record["metadata_" + el.attrib["key"]] = el.attrib["value"] # Dump any WorkoutEvent in a nested list for the moment record["workout_events"] = [el.attrib for el in workout.findall("WorkoutEvent")] - pk = db["workouts"].insert(record, alter=True, hash_id="id").last_pk + + record_id_key = "id" + if record.get("metadata_HKExternalUUID") and not record.get("id"): + record_id_key = "metadata_HKExternalUUID" + + if not record.get(record_id_key): + print(f"No ID for record: {record}") + return + + pk = db["workouts"].insert(record, alter=True, hash_id=record_id_key).last_pk # Handle embedded WorkoutRoute/Location points points = [ #