Skip to content

Commit a2255c8

Browse files
committed
Fixed typos
Added more detailed example code New version
1 parent 25c976a commit a2255c8

3 files changed

Lines changed: 98 additions & 21 deletions

File tree

README.md

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,120 @@ from garminconnect import (
2626
GarminConnectAuthenticationError,
2727
)
2828

29+
"""
30+
Enable debug logging
31+
"""
32+
#import logging
33+
#logging.basicConfig(level=logging.DEBUG)
34+
2935
today = date.today()
36+
37+
38+
"""
39+
Initialize client with credentials
40+
"""
3041
client = Garmin(YOUR_EMAIL, YOUR_PASSWORD)
3142

43+
3244
"""
33-
Login to portal using specified credentials
45+
Login to portal
3446
"""
3547
try:
36-
client = Garmin(YOUR_EMAIL, YOUR_PASSWORD)
48+
client.login()
3749
except (
3850
GarminConnectConnectionError,
3951
GarminConnectAuthenticationError,
4052
GarminConnectTooManyRequestsError,
41-
)
42-
as err:
43-
print("Error occured during Garmin Connect Client setup: %s", err)
44-
return
53+
) as err:
54+
print("Error occured during Garmin Connect Client login: %s" % err)
55+
quit()
4556
except Exception: # pylint: disable=broad-except
46-
print("Unknown error occured during Garmin Connect Client setup")
47-
return
57+
print("Unknown error occured during Garmin Connect Client login")
58+
quit()
59+
4860

4961
"""
50-
Get full name
62+
Get full name from profile
5163
"""
52-
print(client.get_full_name())
64+
try:
65+
print(client.get_full_name())
66+
except (
67+
GarminConnectConnectionError,
68+
GarminConnectAuthenticationError,
69+
GarminConnectTooManyRequestsError,
70+
) as err:
71+
print("Error occured during Garmin Connect Client get full name: %s" % err)
72+
quit()
73+
except Exception: # pylint: disable=broad-except
74+
print("Unknown error occured during Garmin Connect Client get full name")
75+
quit()
76+
5377

5478
"""
55-
Get unit system
79+
Get unit system from profile
5680
"""
57-
print(client.get_unit_system())
81+
try:
82+
print(client.get_unit_system())
83+
except (
84+
GarminConnectConnectionError,
85+
GarminConnectAuthenticationError,
86+
GarminConnectTooManyRequestsError,
87+
) as err:
88+
print("Error occured during Garmin Connect Client get unit system: %s" % err)
89+
quit()
90+
except Exception: # pylint: disable=broad-except
91+
print("Unknown error occured during Garmin Connect Client get unit system")
92+
quit()
93+
5894

5995
"""
60-
Fetch activities data
96+
Get activity data
6197
"""
62-
print(client.get_stats(today.isoformat()))
98+
try:
99+
print(client.get_stats(today.isoformat()))
100+
except (
101+
GarminConnectConnectionError,
102+
GarminConnectAuthenticationError,
103+
GarminConnectTooManyRequestsError,
104+
) as err:
105+
print("Error occured during Garmin Connect Client get stats: %s" % err)
106+
quit()
107+
except Exception: # pylint: disable=broad-except
108+
print("Unknown error occured during Garmin Connect Client get stats")
109+
quit()
110+
63111

64112
"""
65-
Fetch logged heart rates
113+
Get heart rate data
66114
"""
67-
print(client.get_heart_rates(today.isoformat()))
115+
try:
116+
print(client.get_heart_rates(today.isoformat()))
117+
except (
118+
GarminConnectConnectionError,
119+
GarminConnectAuthenticationError,
120+
GarminConnectTooManyRequestsError,
121+
) as err:
122+
print("Error occured during Garmin Connect Client get heart rates: %s" % err)
123+
quit()
124+
except Exception: # pylint: disable=broad-except
125+
print("Unknown error occured during Garmin Connect Client get heart rates")
126+
quit()
127+
68128

69129
"""
70-
Fetch body composition rates
130+
Get body composition data
71131
"""
72-
print(client.get_body_composition(today.isoformat()))
132+
try:
133+
print(client.get_body_composition(today.isoformat()))
134+
except (
135+
GarminConnectConnectionError,
136+
GarminConnectAuthenticationError,
137+
GarminConnectTooManyRequestsError,
138+
) as err:
139+
print("Error occured during Garmin Connect Client get body composition: %s" % err)
140+
quit()
141+
except Exception: # pylint: disable=broad-except
142+
print("Unknown error occured during Garmin Connect Client get body composition")
143+
quit()
144+
73145
```

garminconnect/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def get_unit_system(self):
139139
"""
140140
return self.unit_system
141141

142+
def get_stats_and_body(self, cdate):
143+
"""
144+
Return activity data and body composition
145+
"""
146+
return self.get_stats(cdate) + self.get_body_composition(cdate)
142147

143148
def get_stats(self, cdate): # cDate = 'YYY-mm-dd'
144149
"""
@@ -201,13 +206,13 @@ def get_body_composition(self, cdate): # cDate = 'YYYY-mm-dd'
201206
Fetch available body composition data (only for cDate)
202207
"""
203208
bodycompositionurl = self.url_body_composition + '?startDate=' + cdate + '&endDate=' + cdate
204-
self.logger.debug("Fetching body compostion with url %s", bodycompositionurl)
209+
self.logger.debug("Fetching body composition with url %s", bodycompositionurl)
205210
try:
206211
response = self.req.get(bodycompositionurl, headers=self.headers)
207212
self.logger.debug("Body Composition response code %s, and json %s", response.status_code, response.json())
208213
response.raise_for_status()
209214
except requests.exceptions.HTTPError as err:
210-
self.logger.debug("Exception occured during body compostion retrieval - perhaps session expired - trying relogin: %s" % err)
215+
self.logger.debug("Exception occured during body composition retrieval - perhaps session expired - trying relogin: %s" % err)
211216
self.login(self.email, self.password)
212217
try:
213218
response = self.req.get(bodycompositionurl, headers=self.headers)

garminconnect/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22
"""Python 3 API wrapper for Garmin Connect to get your statistics."""
33

4-
__version__ = "0.1.8"
4+
__version__ = "0.1.9"

0 commit comments

Comments
 (0)