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 = [ #