Skip to content

Commit

Permalink
Fixed typos
Browse files Browse the repository at this point in the history
Added more detailed example code
New version
  • Loading branch information
cyberjunky committed Feb 22, 2020
1 parent 25c976a commit a2255c8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 21 deletions.
108 changes: 90 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,120 @@ from garminconnect import (
GarminConnectAuthenticationError,
)

"""
Enable debug logging
"""
#import logging
#logging.basicConfig(level=logging.DEBUG)

today = date.today()


"""
Initialize client with credentials
"""
client = Garmin(YOUR_EMAIL, YOUR_PASSWORD)


"""
Login to portal using specified credentials
Login to portal
"""
try:
client = Garmin(YOUR_EMAIL, YOUR_PASSWORD)
client.login()
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,
)
as err:
print("Error occured during Garmin Connect Client setup: %s", err)
return
) as err:
print("Error occured during Garmin Connect Client login: %s" % err)
quit()
except Exception: # pylint: disable=broad-except
print("Unknown error occured during Garmin Connect Client setup")
return
print("Unknown error occured during Garmin Connect Client login")
quit()


"""
Get full name
Get full name from profile
"""
print(client.get_full_name())
try:
print(client.get_full_name())
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,
) as err:
print("Error occured during Garmin Connect Client get full name: %s" % err)
quit()
except Exception: # pylint: disable=broad-except
print("Unknown error occured during Garmin Connect Client get full name")
quit()


"""
Get unit system
Get unit system from profile
"""
print(client.get_unit_system())
try:
print(client.get_unit_system())
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,
) as err:
print("Error occured during Garmin Connect Client get unit system: %s" % err)
quit()
except Exception: # pylint: disable=broad-except
print("Unknown error occured during Garmin Connect Client get unit system")
quit()


"""
Fetch activities data
Get activity data
"""
print(client.get_stats(today.isoformat()))
try:
print(client.get_stats(today.isoformat()))
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,
) as err:
print("Error occured during Garmin Connect Client get stats: %s" % err)
quit()
except Exception: # pylint: disable=broad-except
print("Unknown error occured during Garmin Connect Client get stats")
quit()


"""
Fetch logged heart rates
Get heart rate data
"""
print(client.get_heart_rates(today.isoformat()))
try:
print(client.get_heart_rates(today.isoformat()))
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,
) as err:
print("Error occured during Garmin Connect Client get heart rates: %s" % err)
quit()
except Exception: # pylint: disable=broad-except
print("Unknown error occured during Garmin Connect Client get heart rates")
quit()


"""
Fetch body composition rates
Get body composition data
"""
print(client.get_body_composition(today.isoformat()))
try:
print(client.get_body_composition(today.isoformat()))
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,
) as err:
print("Error occured during Garmin Connect Client get body composition: %s" % err)
quit()
except Exception: # pylint: disable=broad-except
print("Unknown error occured during Garmin Connect Client get body composition")
quit()

```
9 changes: 7 additions & 2 deletions garminconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ def get_unit_system(self):
"""
return self.unit_system

def get_stats_and_body(self, cdate):
"""
Return activity data and body composition
"""
return self.get_stats(cdate) + self.get_body_composition(cdate)

def get_stats(self, cdate): # cDate = 'YYY-mm-dd'
"""
Expand Down Expand Up @@ -201,13 +206,13 @@ def get_body_composition(self, cdate): # cDate = 'YYYY-mm-dd'
Fetch available body composition data (only for cDate)
"""
bodycompositionurl = self.url_body_composition + '?startDate=' + cdate + '&endDate=' + cdate
self.logger.debug("Fetching body compostion with url %s", bodycompositionurl)
self.logger.debug("Fetching body composition with url %s", bodycompositionurl)
try:
response = self.req.get(bodycompositionurl, headers=self.headers)
self.logger.debug("Body Composition response code %s, and json %s", response.status_code, response.json())
response.raise_for_status()
except requests.exceptions.HTTPError as err:
self.logger.debug("Exception occured during body compostion retrieval - perhaps session expired - trying relogin: %s" % err)
self.logger.debug("Exception occured during body composition retrieval - perhaps session expired - trying relogin: %s" % err)
self.login(self.email, self.password)
try:
response = self.req.get(bodycompositionurl, headers=self.headers)
Expand Down
2 changes: 1 addition & 1 deletion garminconnect/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
"""Python 3 API wrapper for Garmin Connect to get your statistics."""

__version__ = "0.1.8"
__version__ = "0.1.9"

0 comments on commit a2255c8

Please sign in to comment.