@@ -4,7 +4,7 @@ Python 3 API wrapper for Garmin Connect to get your statistics.
44
55## About
66
7- This package allows you to request your activity and health data you gather on Garmin Connect.
7+ This package allows you to request your device, activity and health data from your Garmin Connect account .
88See https://connect.garmin.com/
99
1010
@@ -32,8 +32,8 @@ from datetime import date
3232"""
3333Enable debug logging
3434"""
35- # import logging
36- # logging.basicConfig(level=logging.DEBUG)
35+ import logging
36+ logging.basicConfig(level = logging.DEBUG )
3737
3838today = date.today()
3939
@@ -42,6 +42,8 @@ today = date.today()
4242Initialize Garmin client with credentials
4343Only needed when your program is initialized
4444"""
45+ print (" Garmin(email, password)" )
46+ print (" ----------------------------------------------------------------------------------------" )
4547try :
4648 client = Garmin(YOUR_EMAIL , YOUR_PASSWORD )
4749except (
@@ -61,6 +63,8 @@ Login to Garmin Connect portal
6163Only needed at start of your program
6264The library will try to relogin when session expires
6365"""
66+ print (" client.login()" )
67+ print (" ----------------------------------------------------------------------------------------" )
6468try :
6569 client.login()
6670except (
@@ -78,6 +82,8 @@ except Exception: # pylint: disable=broad-except
7882"""
7983Get full name from profile
8084"""
85+ print (" client.get_full_name()" )
86+ print (" ----------------------------------------------------------------------------------------" )
8187try :
8288 print (client.get_full_name())
8389except (
@@ -95,6 +101,8 @@ except Exception: # pylint: disable=broad-except
95101"""
96102Get unit system from profile
97103"""
104+ print (" client.get_unit_system()" )
105+ print (" ----------------------------------------------------------------------------------------" )
98106try :
99107 print (client.get_unit_system())
100108except (
@@ -112,6 +120,8 @@ except Exception: # pylint: disable=broad-except
112120"""
113121Get activity data
114122"""
123+ print (" client.get_stats(%s )" , today.isoformat())
124+ print (" ----------------------------------------------------------------------------------------" )
115125try :
116126 print (client.get_stats(today.isoformat()))
117127except (
@@ -125,9 +135,12 @@ except Exception: # pylint: disable=broad-except
125135 print (" Unknown error occurred during Garmin Connect Client get stats" )
126136 quit ()
127137
138+
128139"""
129140Get steps data
130141"""
142+ print (" client.get_steps_data\(%s \)" , today.isoformat())
143+ print (" ----------------------------------------------------------------------------------------" )
131144try :
132145 print (client.get_steps_data(today.isoformat()))
133146except (
@@ -141,9 +154,12 @@ except Exception: # pylint: disable=broad-except
141154 print (" Unknown error occurred during Garmin Connect Client get steps data" )
142155 quit ()
143156
157+
144158"""
145159Get heart rate data
146160"""
161+ print (" client.get_heart_rates(%s )" , today.isoformat())
162+ print (" ----------------------------------------------------------------------------------------" )
147163try :
148164 print (client.get_heart_rates(today.isoformat()))
149165except (
@@ -161,6 +177,8 @@ except Exception: # pylint: disable=broad-except
161177"""
162178Get body composition data
163179"""
180+ print (" client.get_body_composition(%s )" , today.isoformat())
181+ print (" ----------------------------------------------------------------------------------------" )
164182try :
165183 print (client.get_body_composition(today.isoformat()))
166184except (
@@ -178,6 +196,8 @@ except Exception: # pylint: disable=broad-except
178196"""
179197Get stats and body composition data
180198"""
199+ print (" client.get_stats_and_body_composition(%s )" , today.isoformat())
200+ print (" ----------------------------------------------------------------------------------------" )
181201try :
182202 print (client.get_stats_and_body(today.isoformat()))
183203except (
@@ -195,6 +215,8 @@ except Exception: # pylint: disable=broad-except
195215"""
196216Get activities data
197217"""
218+ print (" client.get_activities(0,1)" )
219+ print (" ----------------------------------------------------------------------------------------" )
198220try :
199221 activities = client.get_activities(0 ,1 ) # 0=start, 1=limit
200222 print (activities)
@@ -209,28 +231,35 @@ except Exception: # pylint: disable=broad-except
209231 print (" Unknown error occurred during Garmin Connect Client get activities" )
210232 quit ()
211233
234+
212235"""
213236Download an Activity
214237"""
215-
216238try :
217- for activity in activities:
218- activity_id = activity[" activityId" ]
219-
220- gpx_data = client.download_activity(activity_id, dl_fmt = client.ActivityDownloadFormat.GPX )
221- output_file = f " ./ { str (activity_id)} .gpx "
222- with open (output_file, " wb" ) as fb:
223- fb.write(gpx_data)
224-
225- tcx_data = client.download_activity(activity_id, dl_fmt = client.ActivityDownloadFormat.TCX )
226- output_file = f " ./ { str (activity_id)} .tcx "
227- with open (output_file, " wb" ) as fb:
228- fb.write(tcx_data)
229-
230- zip_data = client.download_activity(activity_id, dl_fmt = client.ActivityDownloadFormat.ORIGINAL )
231- output_file = f " ./ { str (activity_id)} .zip "
232- with open (output_file, " wb" ) as fb:
233- fb.write(zip_data)
239+ for activity in activities:
240+ activity_id = activity[" activityId" ]
241+ print (" client.download_activities(%s )" , activity_id)
242+ print (" ----------------------------------------------------------------------------------------" )
243+
244+ gpx_data = client.download_activity(activity_id, dl_fmt = client.ActivityDownloadFormat.GPX )
245+ output_file = f " ./ { str (activity_id)} .gpx "
246+ with open (output_file, " wb" ) as fb:
247+ fb.write(gpx_data)
248+
249+ tcx_data = client.download_activity(activity_id, dl_fmt = client.ActivityDownloadFormat.TCX )
250+ output_file = f " ./ { str (activity_id)} .tcx "
251+ with open (output_file, " wb" ) as fb:
252+ fb.write(tcx_data)
253+
254+ zip_data = client.download_activity(activity_id, dl_fmt = client.ActivityDownloadFormat.ORIGINAL )
255+ output_file = f " ./ { str (activity_id)} .zip "
256+ with open (output_file, " wb" ) as fb:
257+ fb.write(zip_data)
258+
259+ csv_data = client.download_activity(activity_id, dl_fmt = client.ActivityDownloadFormat.CSV )
260+ output_file = f " ./ { str (activity_id)} .csv "
261+ with open (output_file, " wb" ) as fb:
262+ fb.write(csv_data)
234263except (
235264 GarminConnectConnectionError,
236265 GarminConnectAuthenticationError,
@@ -242,9 +271,12 @@ except Exception: # pylint: disable=broad-except
242271 print (" Unknown error occurred during Garmin Connect Client get activity data" )
243272 quit ()
244273
274+
245275"""
246276Get sleep data
247277"""
278+ print (" client.get_sleep_data(%s )" , today.isoformat())
279+ print (" ----------------------------------------------------------------------------------------" )
248280try :
249281 print (client.get_sleep_data(today.isoformat()))
250282except (
@@ -257,4 +289,46 @@ except (
257289except Exception : # pylint: disable=broad-except
258290 print (" Unknown error occurred during Garmin Connect Client get sleep data" )
259291 quit ()
292+
293+
294+ """
295+ Get devices
296+ """
297+ print (" client.get_devices()" )
298+ print (" ----------------------------------------------------------------------------------------" )
299+ try :
300+ devices = client.get_devices()
301+ print (devices)
302+ except (
303+ GarminConnectConnectionError,
304+ GarminConnectAuthenticationError,
305+ GarminConnectTooManyRequestsError,
306+ ) as err:
307+ print (" Error occurred during Garmin Connect Client get devices: %s " % err)
308+ quit ()
309+ except Exception : # pylint: disable=broad-except
310+ print (" Unknown error occurred during Garmin Connect Client get devices" )
311+ quit ()
312+
313+
314+ """
315+ Get device settings
316+ """
317+ try :
318+ for device in devices:
319+ device_id = device[" deviceId" ]
320+ print (" client.get_device_settings(%s )" , device_id)
321+ print (" ----------------------------------------------------------------------------------------" )
322+
323+ print (client.get_device_settings(device_id))
324+ except (
325+ GarminConnectConnectionError,
326+ GarminConnectAuthenticationError,
327+ GarminConnectTooManyRequestsError,
328+ ) as err:
329+ print (" Error occurred during Garmin Connect Client get device settings: %s " % err)
330+ quit ()
331+ except Exception : # pylint: disable=broad-except
332+ print (" Unknown error occurred during Garmin Connect Client get device settings" )
333+ quit ()
260334```
0 commit comments