Skip to content

Commit e0fa846

Browse files
author
k0rventen
committed
feat: use case insensitive search on export.xml to fix #8
1 parent 4cf9c01 commit e0fa846

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

ingester/app.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
into influx db datapoints
44
"""
55
import os
6+
import re
67
import time
78
import xml.etree.ElementTree as etree
89
from datetime import datetime as dt
@@ -15,8 +16,8 @@
1516

1617
ZIP_PATH = "/export.zip"
1718
ROUTES_PATH = "/export/apple_health_export/workout-routes/"
18-
EXPORT_PATH = "/export/apple_health_export/export.xml"
19-
19+
EXPORT_PATH = "/export/apple_health_export"
20+
EXPORT_XML_REGEX = re.compile("export.xml",re.IGNORECASE)
2021

2122
def parse_float_with_try(v: Any) -> Union[float, int]:
2223
"""convert v to float or 0"""
@@ -127,12 +128,16 @@ def process_workout_routes(client: InfluxDBClient) -> None:
127128

128129

129130
def process_health_data(client: InfluxDBClient) -> None:
130-
if not os.path.exists(EXPORT_PATH):
131-
print("No export.xml file found, skipping ...")
131+
export_xml_files = [f for f in os.listdir(EXPORT_PATH) if EXPORT_XML_REGEX.match(f)]
132+
if not export_xml_files:
133+
print("No export file found, skipping...")
132134
return
135+
136+
export_file = os.path.join(EXPORT_PATH,export_xml_files[0])
137+
print("Export file is",export_file)
133138
records = []
134139
total_count = 0
135-
for _, elem in etree.iterparse(EXPORT_PATH):
140+
for _, elem in etree.iterparse(export_file):
136141
if elem.tag == "Record":
137142
records.append(format_record(elem))
138143
elem.clear()
@@ -155,7 +160,7 @@ def process_health_data(client: InfluxDBClient) -> None:
155160

156161

157162
if __name__ == "__main__":
158-
print("Unzipping the export file ...")
163+
print("Unzipping the export file...")
159164
try:
160165
unpack_archive(ZIP_PATH, "/export")
161166
except Exception as unzip_err:

0 commit comments

Comments
 (0)