From e2b2cbff295c51f48618d93fa69bf065f6d7560c Mon Sep 17 00:00:00 2001 From: Elliot <3186037+elliot-100@users.noreply.github.com> Date: Sat, 20 Apr 2024 22:19:27 +0100 Subject: [PATCH 1/2] refactor: pass params to `clientsession.get()` instead of compiling into URL; extract class constant --- spond/spond.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/spond/spond.py b/spond/spond.py index 1d19f79..b102be3 100644 --- a/spond/spond.py +++ b/spond/spond.py @@ -11,6 +11,9 @@ class AuthenticationError(Exception): class Spond: + + DT_FORMAT = "%Y-%m-%dT00:00:00.000Z" + def __init__(self, username, password): self.username = username self.password = password @@ -280,23 +283,25 @@ async def get_events( list of dict Events; each event is a dict. """ - url = ( - f"{self.api_url}sponds/?" - f"max={max_events}" - f"&scheduled={include_scheduled}" - ) + url = f"{self.api_url}sponds/" + params = { + "max": str(max_events), + "scheduled": str(include_scheduled), + } if max_end: - url += f"&maxEndTimestamp={max_end.strftime('%Y-%m-%dT00:00:00.000Z')}" + params["maxEndTimestamp"] = max_end.strftime(self.DT_FORMAT) if max_start: - url += f"&maxStartTimestamp={max_start.strftime('%Y-%m-%dT00:00:00.000Z')}" + params["maxStartTimestamp"] = max_start.strftime(self.DT_FORMAT) if min_end: - url += f"&minEndTimestamp={min_end.strftime('%Y-%m-%dT00:00:00.000Z')}" + params["minEndTimestamp"] = min_end.strftime(self.DT_FORMAT) if min_start: - url += f"&minStartTimestamp={min_start.strftime('%Y-%m-%dT00:00:00.000Z')}" + params["minStartTimestamp"] = min_start.strftime(self.DT_FORMAT) if group_id: - url += f"&groupId={group_id}" + params["groupId"] = group_id - async with self.clientsession.get(url, headers=self.auth_headers) as r: + async with self.clientsession.get( + url, headers=self.auth_headers, params=params + ) as r: self.events = await r.json() return self.events From 22d72986397f2e25aa0359043bf81c91d6bce67b Mon Sep 17 00:00:00 2001 From: Elliot <3186037+elliot-100@users.noreply.github.com> Date: Mon, 20 May 2024 13:01:18 +0100 Subject: [PATCH 2/2] add: `subgroup_id` parameter to `get_events()`; document --- README.md | 4 ++-- spond/spond.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00191ea..43342d3 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,10 @@ asyncio.run(main()) Get details of all your group memberships and all members of those groups. -### get_events([group_id, include_scheduled, max_end, min_end, max_start, min_start, max_events]) +### get_events([group_id, subgroup_id, include_scheduled, max_end, min_end, max_start, min_start, max_events]) Get details of events, limited to 100 by default. -Optional parameters allow filtering by start and end datetimes, group; more events to be returned; inclusion of 'scheduled' events. +Optional parameters allow filtering by start and end datetimes, group and subgroup; more events to be returned; inclusion of 'scheduled' events. ### get_person() Get a member's details. diff --git a/spond/spond.py b/spond/spond.py index b102be3..9eb71a5 100644 --- a/spond/spond.py +++ b/spond/spond.py @@ -237,6 +237,7 @@ async def send_message(self, text, user=None, group_uid=None, chat_id=None): async def get_events( self, group_id: Optional[str] = None, + subgroup_id: Optional[str] = None, include_scheduled: bool = False, max_end: Optional[datetime] = None, min_end: Optional[datetime] = None, @@ -252,6 +253,8 @@ async def get_events( ---------- group_id : str, optional Uses `GroupId` API parameter. + subgroup_id : str, optional + Uses `subgroupId` API parameter. include_scheduled : bool, optional Include scheduled events. (TO DO: probably events for which invites haven't been sent yet?) @@ -298,6 +301,8 @@ async def get_events( params["minStartTimestamp"] = min_start.strftime(self.DT_FORMAT) if group_id: params["groupId"] = group_id + if subgroup_id: + params["subgroupId"] = subgroup_id async with self.clientsession.get( url, headers=self.auth_headers, params=params