From 546b13428e84ecf52f5f80aaf3ddcc7f50e4b38f Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 30 Dec 2023 13:27:19 -0500 Subject: [PATCH] membershipworks: Allow get_events_list to use end date, retrieve categories --- membershipworks/membershipworks_api.py | 27 ++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/membershipworks/membershipworks_api.py b/membershipworks/membershipworks_api.py index 74bab99..538830e 100644 --- a/membershipworks/membershipworks_api.py +++ b/membershipworks/membershipworks_api.py @@ -238,14 +238,25 @@ class MembershipWorks: members = self.get_members(folders, ",".join(fields.keys())) return members - def get_events_list(self, start_date: datetime.datetime): - """Retrive a list of events since start_date""" - r = self.sess.get( - BASE_URL + "/v2/events", - params={ - "sdp": start_date.strftime("%s"), - }, - ) + def get_events_list( + self, + start_date: datetime.datetime = None, + end_date: datetime.datetime = None, + categories=False, + ): + """Retrive a list of events between `start_date` and `end_date`, optionally including category information""" + if start_date is None and end_date is None: + raise ValueError("Must specify one of start_date or end_date") + + params = {} + if start_date is not None: + params["sdp"] = start_date.strftime("%s") + if end_date is not None: + params["edp"] = end_date.strftime("%s") + if categories is not None: + params["_st"] = "" + + r = self.sess.get(BASE_URL + "/v2/events", params=params) return r.json() def get_event_by_eid(self, eid: str):