Skip to content

Commit

Permalink
Updated version and README
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunky committed Sep 20, 2020
1 parent f8d4b58 commit 33f5cd9
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 22 deletions.
116 changes: 95 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Python 3 API wrapper for Garmin Connect to get your statistics.

## About

This package allows you to request your activity and health data you gather on Garmin Connect.
This package allows you to request your device, activity and health data from your Garmin Connect account.
See https://connect.garmin.com/


Expand Down Expand Up @@ -32,8 +32,8 @@ from datetime import date
"""
Enable debug logging
"""
#import logging
#logging.basicConfig(level=logging.DEBUG)
import logging
logging.basicConfig(level=logging.DEBUG)

today = date.today()

Expand All @@ -42,6 +42,8 @@ today = date.today()
Initialize Garmin client with credentials
Only needed when your program is initialized
"""
print("Garmin(email, password)")
print("----------------------------------------------------------------------------------------")
try:
client = Garmin(YOUR_EMAIL, YOUR_PASSWORD)
except (
Expand All @@ -61,6 +63,8 @@ Login to Garmin Connect portal
Only needed at start of your program
The library will try to relogin when session expires
"""
print("client.login()")
print("----------------------------------------------------------------------------------------")
try:
client.login()
except (
Expand All @@ -78,6 +82,8 @@ except Exception: # pylint: disable=broad-except
"""
Get full name from profile
"""
print("client.get_full_name()")
print("----------------------------------------------------------------------------------------")
try:
print(client.get_full_name())
except (
Expand All @@ -95,6 +101,8 @@ except Exception: # pylint: disable=broad-except
"""
Get unit system from profile
"""
print("client.get_unit_system()")
print("----------------------------------------------------------------------------------------")
try:
print(client.get_unit_system())
except (
Expand All @@ -112,6 +120,8 @@ except Exception: # pylint: disable=broad-except
"""
Get activity data
"""
print("client.get_stats(%s)", today.isoformat())
print("----------------------------------------------------------------------------------------")
try:
print(client.get_stats(today.isoformat()))
except (
Expand All @@ -125,9 +135,12 @@ except Exception: # pylint: disable=broad-except
print("Unknown error occurred during Garmin Connect Client get stats")
quit()


"""
Get steps data
"""
print("client.get_steps_data\(%s\)", today.isoformat())
print("----------------------------------------------------------------------------------------")
try:
print(client.get_steps_data(today.isoformat()))
except (
Expand All @@ -141,9 +154,12 @@ except Exception: # pylint: disable=broad-except
print("Unknown error occurred during Garmin Connect Client get steps data")
quit()


"""
Get heart rate data
"""
print("client.get_heart_rates(%s)", today.isoformat())
print("----------------------------------------------------------------------------------------")
try:
print(client.get_heart_rates(today.isoformat()))
except (
Expand All @@ -161,6 +177,8 @@ except Exception: # pylint: disable=broad-except
"""
Get body composition data
"""
print("client.get_body_composition(%s)", today.isoformat())
print("----------------------------------------------------------------------------------------")
try:
print(client.get_body_composition(today.isoformat()))
except (
Expand All @@ -178,6 +196,8 @@ except Exception: # pylint: disable=broad-except
"""
Get stats and body composition data
"""
print("client.get_stats_and_body_composition(%s)", today.isoformat())
print("----------------------------------------------------------------------------------------")
try:
print(client.get_stats_and_body(today.isoformat()))
except (
Expand All @@ -195,6 +215,8 @@ except Exception: # pylint: disable=broad-except
"""
Get activities data
"""
print("client.get_activities(0,1)")
print("----------------------------------------------------------------------------------------")
try:
activities = client.get_activities(0,1) # 0=start, 1=limit
print(activities)
Expand All @@ -209,28 +231,35 @@ except Exception: # pylint: disable=broad-except
print("Unknown error occurred during Garmin Connect Client get activities")
quit()


"""
Download an Activity
"""

try:
for activity in activities:
activity_id = activity["activityId"]

gpx_data = client.download_activity(activity_id, dl_fmt=client.ActivityDownloadFormat.GPX)
output_file = f"./{str(activity_id)}.gpx"
with open(output_file, "wb") as fb:
fb.write(gpx_data)

tcx_data = client.download_activity(activity_id, dl_fmt=client.ActivityDownloadFormat.TCX)
output_file = f"./{str(activity_id)}.tcx"
with open(output_file, "wb") as fb:
fb.write(tcx_data)

zip_data = client.download_activity(activity_id, dl_fmt=client.ActivityDownloadFormat.ORIGINAL)
output_file = f"./{str(activity_id)}.zip"
with open(output_file, "wb") as fb:
fb.write(zip_data)
for activity in activities:
activity_id = activity["activityId"]
print("client.download_activities(%s)", activity_id)
print("----------------------------------------------------------------------------------------")

gpx_data = client.download_activity(activity_id, dl_fmt=client.ActivityDownloadFormat.GPX)
output_file = f"./{str(activity_id)}.gpx"
with open(output_file, "wb") as fb:
fb.write(gpx_data)

tcx_data = client.download_activity(activity_id, dl_fmt=client.ActivityDownloadFormat.TCX)
output_file = f"./{str(activity_id)}.tcx"
with open(output_file, "wb") as fb:
fb.write(tcx_data)

zip_data = client.download_activity(activity_id, dl_fmt=client.ActivityDownloadFormat.ORIGINAL)
output_file = f"./{str(activity_id)}.zip"
with open(output_file, "wb") as fb:
fb.write(zip_data)

csv_data = client.download_activity(activity_id, dl_fmt=client.ActivityDownloadFormat.CSV)
output_file = f"./{str(activity_id)}.csv"
with open(output_file, "wb") as fb:
fb.write(csv_data)
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
Expand All @@ -242,9 +271,12 @@ except Exception: # pylint: disable=broad-except
print("Unknown error occurred during Garmin Connect Client get activity data")
quit()


"""
Get sleep data
"""
print("client.get_sleep_data(%s)", today.isoformat())
print("----------------------------------------------------------------------------------------")
try:
print(client.get_sleep_data(today.isoformat()))
except (
Expand All @@ -257,4 +289,46 @@ except (
except Exception: # pylint: disable=broad-except
print("Unknown error occurred during Garmin Connect Client get sleep data")
quit()


"""
Get devices
"""
print("client.get_devices()")
print("----------------------------------------------------------------------------------------")
try:
devices = client.get_devices()
print(devices)
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,
) as err:
print("Error occurred during Garmin Connect Client get devices: %s" % err)
quit()
except Exception: # pylint: disable=broad-except
print("Unknown error occurred during Garmin Connect Client get devices")
quit()


"""
Get device settings
"""
try:
for device in devices:
device_id = device["deviceId"]
print("client.get_device_settings(%s)", device_id)
print("----------------------------------------------------------------------------------------")

print(client.get_device_settings(device_id))
except (
GarminConnectConnectionError,
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,
) as err:
print("Error occurred during Garmin Connect Client get device settings: %s" % err)
quit()
except Exception: # pylint: disable=broad-except
print("Unknown error occurred during Garmin Connect Client get device settings")
quit()
```
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.15"
__version__ = "0.1.16"

0 comments on commit 33f5cd9

Please sign in to comment.