Get all activities at a specific date
This example collects all activities occurring on a specific date in the activities_at_date list. The list is empty if no activities occur that day.
The following logical steps are performed:
- Set the desired date using the
datetime and the ZoneInfo modules.
- Query from the desired date, which the API includes, and retrieve each page.
- Compare start times in the chosen timezone and collect every activity on the desired date.
- Stop when a later date is reached or the API returns an empty page. This relies on activities being returned in chronological order.
- Print each matching activity's name, id, and start time.
| from datetime import datetime
from zoneinfo import ZoneInfo
from pyholdsport import Holdsport, HoldsportActivity
timezone = ZoneInfo("Europe/Copenhagen")
with Holdsport(
holdsport_username="username",
holdsport_password="password",
) as holdsport:
team_id = 123
activity_date = datetime(2026, 3, 13, tzinfo=timezone).date()
activities_at_date: list[HoldsportActivity] = []
page = 1
while True:
activities = holdsport.get_activities(
team_id=team_id,
date=activity_date.isoformat(), # (1)!
page=page,
)
if not activities:
break
reached_later_date = False
for activity in activities:
start_time = datetime.strptime(
activity.starttime, "%Y-%m-%dT%H:%M:%S%z"
)
start_date = start_time.astimezone(timezone).date()
if start_date > activity_date:
# Activities are returned in chronological order.
reached_later_date = True
break
if start_date == activity_date:
activities_at_date.append(activity)
if reached_later_date:
break
page += 1
for activity in activities_at_date:
print(f"Activity name: '{activity.name}'")
print(f"Activity id: {activity.id}")
print(f"Activity start time: {activity.starttime}")
|
- The starting date is inclusive. Querying the target date directly avoids filling the first page with earlier activities. Pagination includes matches beyond the first page.