@@ -119,35 +119,35 @@ def __convert_to_json(cls, object):
119119 return object .__str__ ()
120120
121121 @classmethod
122- def save_json_to_file (cls , filename , json_data , overwite = False ):
122+ def save_json_to_file (cls , filename , json_data , overwrite = False ):
123123 """Save JSON formatted data to a file."""
124124 full_filename = f'{ filename } .json'
125125 exists = os .path .isfile (full_filename )
126- if not exists or overwite :
126+ if not exists or overwrite :
127127 logger .debug ("%s %s" , 'Overwriting' if exists else 'Saving' , full_filename )
128128 with open (full_filename , 'w' ) as file :
129129 file .write (json .dumps (json_data , default = cls .__convert_to_json ))
130130
131- def save_binary_file (self , filename , url , overwite = False ):
131+ def save_binary_file (self , filename , url , overwrite = False ):
132132 """Save binary data to a file."""
133133 exists = os .path .isfile (filename )
134- if not exists or overwite :
134+ if not exists or overwrite :
135135 logger .debug ("%s %s" , 'Overwriting' if exists else 'Saving' , filename )
136136 response = self .garth .get ("connectapi" , url , api = True )
137137 with open (filename , 'wb' ) as file :
138138 for chunk in response :
139139 file .write (chunk )
140140
141- def __get_stat (self , stat_function , directory , date , days , overwite ):
141+ def __get_stat (self , stat_function , directory , date , days , overwrite ):
142142 for day in tqdm (range (0 , days ), unit = 'days' ):
143143 download_date = date + datetime .timedelta (days = day )
144144 # always overwrite for yesterday and today since the last download may have been a partial result
145145 delta = datetime .datetime .now ().date () - download_date
146- stat_function (directory , download_date , overwite or delta .days <= self .download_days_overlap )
146+ stat_function (directory , download_date , overwrite or delta .days <= self .download_days_overlap )
147147 # pause for a second between every page access
148148 time .sleep (1 )
149149
150- def __get_summary_day (self , directory_func , date , overwite = False ):
150+ def __get_summary_day (self , directory_func , date , overwrite = False ):
151151 root_logger .info ("get_summary_day: %s" , date )
152152 date_str = date .strftime ('%Y-%m-%d' )
153153 params = {
@@ -157,14 +157,14 @@ def __get_summary_day(self, directory_func, date, overwite=False):
157157 url = f'{ self .garmin_connect_daily_summary_url } /{ self .display_name } '
158158 json_filename = f'{ directory_func (date .year )} /daily_summary_{ date_str } '
159159 try :
160- self .save_json_to_file (json_filename , self .garth .connectapi (url , params = params ), overwite )
160+ self .save_json_to_file (json_filename , self .garth .connectapi (url , params = params ), overwrite )
161161 except GarthHTTPError as e :
162162 root_logger .error ("Exception getting daily summary: %s" , e )
163163
164- def get_daily_summaries (self , directory_func , date , days , overwite ):
164+ def get_daily_summaries (self , directory_func , date , days , overwrite ):
165165 """Download the daily summary data from Garmin Connect and save to a JSON file."""
166166 root_logger .info ("Getting daily summaries: %s (%d)" , date , days )
167- self .__get_stat (self .__get_summary_day , directory_func , date , days , overwite )
167+ self .__get_stat (self .__get_summary_day , directory_func , date , days , overwrite )
168168
169169 def __get_monitoring_day (self , date ):
170170 root_logger .info ("get_monitoring_day: %s to %s" , date , self .temp_dir )
@@ -186,8 +186,8 @@ def get_monitoring(self, directory_func, date, days):
186186 # pause for a second between every page access
187187 time .sleep (1 )
188188
189- def __get_weight_day (self , directory , day , overwite = False ):
190- root_logger .info ("Checking weight: %s overwite %r" , day , overwite )
189+ def __get_weight_day (self , directory , day , overwrite = False ):
190+ root_logger .info ("Checking weight: %s overwrite %r" , day , overwrite )
191191 date_str = day .strftime ('%Y-%m-%d' )
192192 params = {
193193 'startDate' : date_str ,
@@ -196,14 +196,15 @@ def __get_weight_day(self, directory, day, overwite=False):
196196 }
197197 json_filename = f'{ directory } /weight_{ date_str } '
198198 try :
199- self .save_json_to_file (json_filename , self .garth .connectapi (self .garmin_connect_weight_url , params = params ), overwite )
199+ self .save_json_to_file (json_filename , self .garth .connectapi (self .garmin_connect_weight_url , params = params ), overwrite )
200200 except GarthHTTPError as e :
201201 root_logger .error ("Exception getting daily summary: %s" , e )
202202
203- def get_weight (self , directory , date , days , overwite ):
203+ def get_weight (self , directory , date , days , overwrite ):
204204 """Download the sleep data from Garmin Connect and save to a JSON file."""
205205 root_logger .info ("Getting weight: %s (%d)" , date , days )
206- self .__get_stat (self .__get_weight_day , directory , date , days , overwite )
206+ self .__get_stat (self .__get_weight_day ,
207+ directory , date , days , overwrite )
207208
208209 def __get_activity_summaries (self , start , count ):
209210 root_logger .info ("get_activity_summaries" )
@@ -216,12 +217,13 @@ def __get_activity_summaries(self, start, count):
216217 except GarthHTTPError as e :
217218 root_logger .error ("Exception getting activity summary: %s" , e )
218219
219- def __save_activity_details (self , directory , activity_id_str , overwite ):
220+ def __save_activity_details (self , directory , activity_id_str , overwrite ):
220221 root_logger .debug ("save_activity_details" )
221222 json_filename = f'{ directory } /activity_details_{ activity_id_str } '
222223 try :
223224 url = f'{ self .garmin_connect_activity_service_url } /{ activity_id_str } '
224- self .save_json_to_file (json_filename , self .garth .connectapi (url ), overwite )
225+ self .save_json_to_file (
226+ json_filename , self .garth .connectapi (url ), overwrite )
225227 except GarthHTTPError as e :
226228 root_logger .error ("Exception getting daily summary %s" , e )
227229
@@ -234,7 +236,7 @@ def __save_activity_file(self, activity_id_str):
234236 except GarthHTTPError as e :
235237 root_logger .error ("Exception downloading activity file: %s" , e )
236238
237- def get_activities (self , directory , count , overwite = False ):
239+ def get_activities (self , directory , count , overwrite = False ):
238240 """Download activities files from Garmin Connect and save the raw files."""
239241 self .temp_dir = tempfile .mkdtemp ()
240242 logger .info ("Getting activities: '%s' (%d) temp %s" , directory , count , self .temp_dir )
@@ -244,46 +246,47 @@ def get_activities(self, directory, count, overwite=False):
244246 activity_name_str = conversions .printable (activity .get ('activityName' ))
245247 root_logger .info ("get_activities: %s (%s)" , activity_name_str , activity_id_str )
246248 json_filename = f'{ directory } /activity_{ activity_id_str } '
247- if not os .path .isfile (json_filename + '.json' ) or overwite :
249+ if not os .path .isfile (json_filename + '.json' ) or overwrite :
248250 root_logger .info ("get_activities: %s <- %r" , json_filename , activity )
249- self .__save_activity_details (directory , activity_id_str , overwite )
251+ self .__save_activity_details (directory , activity_id_str , overwrite )
250252 self .save_json_to_file (json_filename , activity )
251- if not os .path .isfile (f'{ directory } /{ activity_id_str } .fit' ) or overwite :
253+ if not os .path .isfile (f'{ directory } /{ activity_id_str } .fit' ) or overwrite :
252254 self .__save_activity_file (activity_id_str )
253255 # pause for a second between every page access
254256 time .sleep (1 )
255257 else :
256258 root_logger .info ("get_activities: skipping download of %s, already present" , activity_id_str )
257259 self .__unzip_files (directory )
258260
259- def get_activity_types (self , directory , overwite ):
261+ def get_activity_types (self , directory , overwrite ):
260262 """Download the activity types from Garmin Connect and save to a JSON file."""
261263 root_logger .info ("get_activity_types: '%s'" , directory )
262264 json_filename = f'{ directory } /activity_types'
263265 try :
264266 url = f'{ self .garmin_connect_activity_service_url } /activityTypes'
265- self .save_json_to_file (json_filename , self .garth .connectapi (url ), overwite )
267+ self .save_json_to_file (
268+ json_filename , self .garth .connectapi (url ), overwrite )
266269 except GarthHTTPError as e :
267270 root_logger .error ("Exception getting activity types: %s" , e )
268271
269- def __get_sleep_day (self , directory , date , overwite = False ):
272+ def __get_sleep_day (self , directory , date , overwrite = False ):
270273 json_filename = f'{ directory } /sleep_{ date } '
271274 params = {
272275 'date' : date .strftime ("%Y-%m-%d" ),
273276 'nonSleepBufferMinutes' : 60
274277 }
275278 url = f'{ self .garmin_connect_sleep_daily_url } /{ self .display_name } '
276279 try :
277- self .save_json_to_file (json_filename , self .garth .connectapi (url , params = params ), overwite )
280+ self .save_json_to_file (json_filename , self .garth .connectapi (url , params = params ), overwrite )
278281 except GarthHTTPError as e :
279282 root_logger .error ("Exception getting daily summary: %s" , e )
280283
281- def get_sleep (self , directory , date , days , overwite ):
284+ def get_sleep (self , directory , date , days , overwrite ):
282285 """Download the sleep data from Garmin Connect and save to a JSON file."""
283286 root_logger .info ("Getting sleep: %s (%d)" , date , days )
284- self .__get_stat (self .__get_sleep_day , directory , date , days , overwite )
287+ self .__get_stat (self .__get_sleep_day , directory , date , days , overwrite )
285288
286- def __get_rhr_day (self , directory , day , overwite = False ):
289+ def __get_rhr_day (self , directory , day , overwrite = False ):
287290 date_str = day .strftime ('%Y-%m-%d' )
288291 json_filename = f'{ directory } /rhr_{ date_str } '
289292 params = {
@@ -293,25 +296,26 @@ def __get_rhr_day(self, directory, day, overwite=False):
293296 }
294297 url = f'{ self .garmin_connect_rhr } /{ self .display_name } '
295298 try :
296- self .save_json_to_file (json_filename , self .garth .connectapi (url , params = params ), overwite )
299+ self .save_json_to_file (json_filename , self .garth .connectapi (
300+ url , params = params ), overwrite )
297301 except GarthHTTPError as e :
298302 root_logger .error ("Exception getting daily summary %s" , e )
299303
300- def get_rhr (self , directory , date , days , overwite ):
304+ def get_rhr (self , directory , date , days , overwrite ):
301305 """Download the resting heart rate data from Garmin Connect and save to a JSON file."""
302306 root_logger .info ("Getting rhr: %s (%d)" , date , days )
303- self .__get_stat (self .__get_rhr_day , directory , date , days , overwite )
307+ self .__get_stat (self .__get_rhr_day , directory , date , days , overwrite )
304308
305- def __get_hydration_day (self , directory_func , day , overwite = False ):
309+ def __get_hydration_day (self , directory_func , day , overwrite = False ):
306310 date_str = day .strftime ('%Y-%m-%d' )
307311 json_filename = f'{ directory_func (day .year )} /hydration_{ date_str } '
308312 url = f'{ self .garmin_connect_daily_hydration_url } /{ date_str } '
309313 try :
310- self .save_json_to_file (json_filename , self .garth .connectapi (url ), overwite )
314+ self .save_json_to_file (json_filename , self .garth .connectapi (url ), overwrite )
311315 except GarthHTTPError as e :
312316 root_logger .error ("Exception getting hydration: %s" , e )
313317
314- def get_hydration (self , directory_func , date , days , overwite ):
318+ def get_hydration (self , directory_func , date , days , overwrite ):
315319 """Download the hydration data from Garmin Connect and save to a JSON file."""
316320 root_logger .info ("Getting hydration: %s (%d)" , date , days )
317- self .__get_stat (self .__get_hydration_day , directory_func , date , days , overwite )
321+ self .__get_stat (self .__get_hydration_day , directory_func , date , days , overwrite )
0 commit comments