Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ authors = [
{name = "Matin Tamizi", email = "mtamizi@duck.com"},
]
dependencies = [
"requests>=2.0.0,<3.0.0",
"pydantic>=2.0.0,<3.0.0",
"pydantic-settings>=2.0.0,<3.0.0",
"requests-oauthlib>=1.3.1,<3.0.0",
"logfire>=2.11,<5.0",
"camoufox>=0.4",
"playwright>=1.40",
]
requires-python = ">=3.10"
readme = "README.md"
license = {text = "MIT"}
classifiers = [
"Development Status :: 7 - Inactive",
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down Expand Up @@ -89,7 +88,7 @@ testing = [
"coverage",
"freezegun",
"pytest",
"pytest-vcr",
"pyyaml>=6.0",
"logfire>=2.11,<5.0",
]

Expand Down
12 changes: 2 additions & 10 deletions src/garth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import warnings

from .data import (
Activity,
BodyBatteryData,
Expand All @@ -16,6 +14,7 @@
WeightData,
)
from .http import Client, client
from .sso import close
from .stats import (
DailyHRV,
DailyHydration,
Expand All @@ -34,14 +33,6 @@
from .version import __version__


warnings.warn(
"Garth is deprecated and no longer maintained. "
"See https://github.com/matin/garth/discussions/222",
DeprecationWarning,
stacklevel=2,
)


__all__ = [
"Activity",
"BodyBatteryData",
Expand Down Expand Up @@ -73,6 +64,7 @@
"WeightData",
"__version__",
"client",
"close",
"configure",
"connectapi",
"download",
Expand Down
30 changes: 18 additions & 12 deletions src/garth/data/_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import builtins
from abc import ABC, abstractmethod
from concurrent.futures import ThreadPoolExecutor
from datetime import date
from itertools import chain

Expand All @@ -9,8 +8,9 @@
from .. import http
from ..utils import date_range, format_end_date


MAX_WORKERS = 10
# Kept for backward compatibility — thread pool is no longer used
# since browser transport cannot be called from multiple threads.
MAX_WORKERS = 1


class Data(ABC):
Expand All @@ -30,22 +30,28 @@ def list(
days: int = 1,
*,
client: http.Client | None = None,
max_workers: int = MAX_WORKERS,
max_workers: int = 1,
) -> builtins.list[Self]:
"""Fetch data for multiple dates sequentially.

Note:
The max_workers parameter is accepted for backward
compatibility but ignored. All requests go through a
single browser page and cannot be parallelized.
"""
client = client or http.client
end = format_end_date(end)

def fetch_date(date_):
if day := cls.get(date_, client=client):
return day

dates = date_range(end, days)
with ThreadPoolExecutor(max_workers=max_workers) as executor:
data = list(executor.map(fetch_date, dates))
data = [day for day in data if day is not None]
data = []
for date_ in dates:
day = cls.get(date_, client=client)
if day is not None:
data.append(day)

return list(
chain.from_iterable(
day if isinstance(day, list) else [day] for day in data
day if isinstance(day, list) else [day]
for day in data
)
)
4 changes: 1 addition & 3 deletions src/garth/exc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from dataclasses import dataclass

from requests import HTTPError


@dataclass
class GarthException(Exception):
Expand All @@ -15,7 +13,7 @@ def __str__(self) -> str:

@dataclass
class GarthHTTPError(GarthException):
error: HTTPError
error: Exception

def __str__(self) -> str:
return f"{self.msg}: {self.error}"
Loading
Loading