def get_garmin_data(username, password): # input: username and passwrod # output: normalised pandas df containing garmain connect data of username # connect garmin client client = Garmin(username, password) client.login() activities = client.get_activities(0, 1000) # store as dataframe df = pd.DataFrame(activities) # make data useable wanted = [ 'activityId', 'activityName', 'startTimeLocal', 'distance', 'duration', 'elevationGain', 'elevationLoss', 'averageSpeed', 'maxSpeed', 'calories', 'averageHR', 'maxHR', 'averageRunningCadenceInStepsPerMinute', 'averageBikingCadenceInRevPerMinute', 'averageSwimCadenceInStrokesPerMinute', 'aerobicTrainingEffect', 'anaerobicTrainingEffect' ] df = df[df.columns.intersection(wanted)] df['duration'] = df['duration'].div(60).round(2) df['activityType'] = df['activityName'].str.split(' ').str[-1] df['startTimeLocal'] = pd.to_datetime(df['startTimeLocal'], errors='coerce') df['startTimeLocal'] = df['startTimeLocal'].dt.date return df
GarminConnectTooManyRequestsError, ) as err: print( "Error occurred during Garmin Connect Client get stats and body composition: %s" % err) quit() except Exception: # pylint: disable=broad-except print( "Unknown error occurred during Garmin Connect Client get stats and body composition" ) quit() """ Get activities data """ try: activities = client.get_activities(0, 1) # 0=start, 1=limit print(activities) except ( GarminConnectConnectionError, GarminConnectAuthenticationError, GarminConnectTooManyRequestsError, ) as err: print("Error occurred during Garmin Connect Client get activities: %s" % err) quit() except Exception: # pylint: disable=broad-except print("Unknown error occurred during Garmin Connect Client get activities") quit() """ Download an Activity """
quit() try: client.login() except ( GarminConnectConnectionError, GarminConnectAuthenticationError, GarminConnectTooManyRequestsError, ) as err: print("Error occurred during Garmin Connect Client login: %s" % err) quit() except Exception: # pylint: disable=broad-except print("Unknown error occurred during Garmin Connect Client login") quit() activities = client.get_activities(0, 1000) act = [[e['activityId'], e['startTimeLocal'], e['distance'], e['averageHR']] for e in activities if e['activityType']['typeKey'] == 'running'] for i, el in enumerate(act): hr_timezones = client.get_activity_hr_in_timezones(el[0]) total_time = sum([e['secsInZone'] for e in hr_timezones]) act[i].append(total_time) zones_1_2 = sum( [e['secsInZone'] for e in hr_timezones if e['zoneNumber'] in [1, 2]]) / total_time act[i].append(zones_1_2) df = pd.DataFrame(act, columns=[ 'activityId', 'date', 'distance', 'averageHR',
except ( GarminConnectConnectionError, GarminConnectAuthenticationError, GarminConnectTooManyRequestsError, ) as err: print( "Error occured during Garmin Connect Client get stats and body composition: %s" % err) quit() except Exception: # pylint: disable=broad-except print( "Unknown error occured during Garmin Connect Client get stats and body composition" ) quit() """ Get activities data """ try: print(client.get_activities(0, 1)) # 0=start, 1=limit except ( GarminConnectConnectionError, GarminConnectAuthenticationError, GarminConnectTooManyRequestsError, ) as err: print("Error occured during Garmin Connect Client get activities: %s" % err) quit() except Exception: # pylint: disable=broad-except print("Unknown error occured during Garmin Connect Client get activities") quit()