Skip to content

Commit

Permalink
Linted, updated version
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunky committed Mar 15, 2024
1 parent 4dab2ab commit a46913e
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ rebuild-lockfiles: .pdm
format: .pdm
pdm run isort $(sources)
pdm run black -l 79 $(sources)
pdm run ruff --fix $(sources)
pdm run ruff check $(sources)

.PHONY: lint ## Lint python source files
lint: .pdm
pdm run isort --check-only $(sources)
pdm run ruff $(sources)
pdm run ruff check $(sources)
pdm run black -l 79 $(sources) --check --diff
pdm run mypy $(sources)

Expand Down
94 changes: 56 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@

```
$ ./example.py
*** Garmin Connect API Demo by cyberjunky ***
1 -- Get full name
2 -- Get unit system
3 -- Get activity data for '2024-01-21'
4 -- Get activity data for '2024-01-21' (compatible with garminconnect-ha)
5 -- Get body composition data for '2024-01-21' (compatible with garminconnect-ha)
6 -- Get body composition data for from '2024-01-14' to '2024-01-21' (to be compatible with garminconnect-ha)
7 -- Get stats and body composition data for '2024-01-21'
8 -- Get steps data for '2024-01-21'
9 -- Get heart rate data for '2024-01-21'
0 -- Get training readiness data for '2024-01-21'
- -- Get daily step data for '2024-01-14' to '2024-01-21'
/ -- Get body battery data for '2024-01-14' to '2024-01-21'
! -- Get floors data for '2024-01-14'
? -- Get blood pressure data for '2024-01-14' to '2024-01-21'
. -- Get training status data for '2024-01-21'
a -- Get resting heart rate data for 2024-01-21'
b -- Get hydration data for '2024-01-21'
c -- Get sleep data for '2024-01-21'
d -- Get stress data for '2024-01-21'
e -- Get respiration data for '2024-01-21'
f -- Get SpO2 data for '2024-01-21'
g -- Get max metric data (like vo2MaxValue and fitnessAge) for '2024-01-21'
3 -- Get activity data for '2024-03-15'
4 -- Get activity data for '2024-03-15' (compatible with garminconnect-ha)
5 -- Get body composition data for '2024-03-15' (compatible with garminconnect-ha)
6 -- Get body composition data for from '2024-03-08' to '2024-03-15' (to be compatible with garminconnect-ha)
7 -- Get stats and body composition data for '2024-03-15'
8 -- Get steps data for '2024-03-15'
9 -- Get heart rate data for '2024-03-15'
0 -- Get training readiness data for '2024-03-15'
- -- Get daily step data for '2024-03-08' to '2024-03-15'
/ -- Get body battery data for '2024-03-08' to '2024-03-15'
! -- Get floors data for '2024-03-08'
? -- Get blood pressure data for '2024-03-08' to '2024-03-15'
. -- Get training status data for '2024-03-15'
a -- Get resting heart rate data for 2024-03-15'
b -- Get hydration data for '2024-03-15'
c -- Get sleep data for '2024-03-15'
d -- Get stress data for '2024-03-15'
e -- Get respiration data for '2024-03-15'
f -- Get SpO2 data for '2024-03-15'
g -- Get max metric data (like vo2MaxValue and fitnessAge) for '2024-03-15'
h -- Get personal record for user
i -- Get earned badges for user
j -- Get adhoc challenges data from start '0' and limit '100'
Expand All @@ -35,35 +34,37 @@ l -- Get badge challenges data from '1' and limit '100'
m -- Get non completed badge challenges data from '1' and limit '100'
n -- Get activities data from start '0' and limit '100'
o -- Get last activity
p -- Download activities data by date from '2024-01-14' to '2024-01-21'
p -- Download activities data by date from '2024-03-08' to '2024-03-15'
r -- Get all kinds of activities data from '0'
s -- Upload activity data from file 'MY_ACTIVITY.fit'
t -- Get all kinds of Garmin device info
u -- Get active goals
v -- Get future goals
w -- Get past goals
y -- Get all Garmin device alarms
x -- Get Heart Rate Variability data (HRV) for '2024-01-21'
z -- Get progress summary from '2024-01-14' to '2024-01-21' for all metrics
x -- Get Heart Rate Variability data (HRV) for '2024-03-15'
z -- Get progress summary from '2024-03-08' to '2024-03-15' for all metrics
A -- Get gear, the defaults, activity types and statistics
B -- Get weight-ins from '2024-01-14' to '2024-01-21'
C -- Get daily weigh-ins for '2024-01-21'
D -- Delete all weigh-ins for '2024-01-21'
E -- Add a weigh-in of 89.6kg on '2024-01-21'
F -- Get virtual challenges/expeditions from '2024-01-14' to '2024-01-21'
G -- Get hill score data from '2024-01-14' to '2024-01-21'
H -- Get endurance score data from '2024-01-14' to '2024-01-21'
I -- Get activities for date '2024-01-21'
B -- Get weight-ins from '2024-03-08' to '2024-03-15'
C -- Get daily weigh-ins for '2024-03-15'
D -- Delete all weigh-ins for '2024-03-15'
E -- Add a weigh-in of 89.6kg on '2024-03-15'
F -- Get virtual challenges/expeditions from '2024-03-08' to '2024-03-15'
G -- Get hill score data from '2024-03-08' to '2024-03-15'
H -- Get endurance score data from '2024-03-08' to '2024-03-15'
I -- Get activities for date '2024-03-15'
J -- Get race predictions
K -- Get all day stress data for '2024-01-21'
L -- Add body composition for '2024-01-21'
K -- Get all day stress data for '2024-03-15'
L -- Add body composition for '2024-03-15'
M -- Set blood pressure '120,80,80,notes='Testing with example.py'
N -- Get user profile/settings
O -- Reload epoch data for 2024-01-21
P -- Get workouts and get and download last one to .fit file
O -- Reload epoch data for 2024-03-15
P -- Get workouts 0-100, get and download last one to .FIT file
R -- Get solar data from your devices
S -- Get pregnancy summary data
Z -- Remove stored login tokens (logout)
q -- Exit
Make your selection:
Make your selection:
```

[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/cyberjunkynl/)
Expand Down Expand Up @@ -105,11 +106,14 @@ make test
To create a development environment to commit code.

```
make .venv
source .venv/bin/activate
pip3 install pdm
pip3 install ruff
pdm init
sudo apt install pre-commit
sudo apt install pre-commit isort black mypy
pip3 install pre-commit
```
Run checks before PR/Commit:
Expand All @@ -119,6 +123,20 @@ make lint
make codespell
```

## Publish

To publish new package (author only)

```
sudo apt install twine
vi ~/.pypirc
[pypi]
username = __token__
password = <PyPI token>
make publish
```

## Example
The tests provide examples of how to use the library.
There is a Jupyter notebook called `reference.ipynb` provided [here](https://github.com/cyberjunky/python-garminconnect/blob/master/reference.ipynb).
Expand Down
16 changes: 9 additions & 7 deletions garminconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def __init__(self, email=None, password=None, is_cn=False):

self.garmin_workouts = "/workout-service"

self.garmin_connect_delete_activity_url = (
"/activity-service/activity"
)
self.garmin_connect_delete_activity_url = "/activity-service/activity"

self.garth = garth.Client(
domain="garmin.cn" if is_cn else "garmin.com"
Expand Down Expand Up @@ -743,19 +741,21 @@ def get_device_settings(self, device_id: str) -> Dict[str, Any]:

return self.connectapi(url)

def get_device_solar_data(self, device_id: str, startdate: str, enddate: str = None) -> Dict[str, Any]:
def get_device_solar_data(
self, device_id: str, startdate: str, enddate=None
) -> Dict[str, Any]:
"""Return solar data for compatible device with 'device_id'"""
if enddate is None:
enddate = startdate
single_day = True
else:
single_day = False

params = {'singleDayView': single_day}
params = {"singleDayView": single_day}

url = f"{self.garmin_connect_solar_url}/{device_id}/{startdate}/{enddate}"

return self.connectapi(url, params=params)['deviceSolarInput']
return self.connectapi(url, params=params)["deviceSolarInput"]

def get_device_alarms(self) -> Dict[str, Any]:
"""Get list of active alarms from all devices."""
Expand Down Expand Up @@ -1170,7 +1170,9 @@ def get_menstrual_calendar_data(self, startdate: str, enddate: str):
"""Return summaries of cycles that have days between startdate and enddate."""

url = f"{self.garmin_connect_menstrual_calendar_url}/{startdate}/{enddate}"
logger.debug(f"Requesting menstrual data for dates {startdate} through {enddate}")
logger.debug(
f"Requesting menstrual data for dates {startdate} through {enddate}"
)

return self.connectapi(url)

Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "garminconnect"
version = "0.2.13"
version = "0.2.14"
description = "Python 3 API wrapper for Garmin Connect"
authors = [
{name = "Ron Klinkien", email = "[email protected]"},
Expand Down Expand Up @@ -43,8 +43,7 @@ line_length = 79
known_first_party = "garminconnect"

[tool.pdm]
package-type = "library"

distribution = true
[tool.pdm.dev-dependencies]
dev = [
"ipython",
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest
pytest-vcr
pytest-cov
coverage
coverage

0 comments on commit a46913e

Please sign in to comment.