diff --git a/README.md b/README.md index 3ca7ac3..64c3e80 100644 --- a/README.md +++ b/README.md @@ -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() + ``` diff --git a/garminconnect/__init__.py b/garminconnect/__init__.py index 3d97c0e..6bcc93d 100644 --- a/garminconnect/__init__.py +++ b/garminconnect/__init__.py @@ -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' """ @@ -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) diff --git a/garminconnect/__version__.py b/garminconnect/__version__.py index 78b65fc..5b528d7 100644 --- a/garminconnect/__version__.py +++ b/garminconnect/__version__.py @@ -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"