dogsheep / healthkit-to-sqlite

Convert an Apple Healthkit export zip to a SQLite database
https://datasette.io/tools/healthkit-to-sqlite
Apache License 2.0
191 stars 9 forks source link

export.xml file name varies with different language settings #11

Closed jarib closed 3 years ago

jarib commented 3 years ago

The XML file exported from my phone has a Norwegian file name – eksport.xml 🙄

I can work around this by unpacking the zip and using --xml, but then I lose the workout points.

Perhaps this could be solved by --localized-xml eksport.xml? Alternatively just fall back to the first XML file in the root folder of the zip.

simonw commented 3 years ago

I'd be happy to teach the tool to look for export.xml or eksport.xml - and then expand that list to other languages.

simonw commented 3 years ago

The "first XML file in the root" solution is probably easier though!

simonw commented 3 years ago

I switched my phone to Spanish and ran an export - I got a file called exportar.zip. Unzipped I still got a apple_ health_export folder but the root contained:

electrocardiograms/
export_cda.xml
exportar.xml
workout-routes/

It looks like export_cda.xml does not have a translated name, so maybe I can ignore it and look for the other .xml file in that directory.

simonw commented 3 years ago

I think the safest thing is to sniff the first few lines of the file. Those should be the same no matter the language that was used:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HealthData [
simonw commented 3 years ago

Checking for either <!DOCTYPE HealthData or <HealthData in the first 1000 bytes should do it.

simonw commented 3 years ago

OK, if you upgrade to the just-released 1.0 this should work (it worked against my Spanish export).

jarib commented 3 years ago

Nice! Works perfectly. Thanks for the quick response and great tooling in general.