33into influx db datapoints
44"""
55import os
6+ import re
67import time
78import xml .etree .ElementTree as etree
89from datetime import datetime as dt
1516
1617ZIP_PATH = "/export.zip"
1718ROUTES_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
2122def 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
129130def 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
157162if __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