From 8291cb62f7e6e35870a4390edb19c99f95efa23b Mon Sep 17 00:00:00 2001 From: olizimmermann Date: Thu, 26 Jan 2023 00:11:21 +0100 Subject: [PATCH 1/2] added update_event function --- spond/spond.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/spond/spond.py b/spond/spond.py index 4c938bf..81dd618 100644 --- a/spond/spond.py +++ b/spond/spond.py @@ -243,3 +243,73 @@ async def get_event(self, uid): for event in self.events: if event["id"] == uid: return event + + + async def update_event(self, event_id, event: dict, updates: dict): + """ + Updates an existing event. + + Parameters: + ---------- + event_id : str + The ID of the event -> e.g. get_events()[0]['id'] + event : dict + The original event dict, unchanged + updates : dict + The changes. e.g. if you want to change the description -> {'description': "New Description with changes"} + + Returns: + ---------- + json results of post command + + """ + if not self.cookie: + await self.login() + + url = f"{self.apiurl}sponds/" + f"{event_id}" + + base_event = {"heading":str, + "description": str, + "spondType":"EVENT", + "startTimestamp":str, + "endTimestamp":str, + "commentsDisabled":False, + "maxAccepted":0, + "rsvpDate":None, + "location":{"id": str, + "feature":str, + "address":str, + "latitude":float, + "longitude":float}, + "owners":[{"id":str}], + "visibility":"INVITEES", + "participantsHidden":False, + "autoReminderType":"DISABLED", + "autoAccept":False, + "payment":{}, + "attachments":[], + "id":str, + "tasks":{"openTasks":[], + "assignedTasks":[{"name":str, + "description":"", + "type":"ASSIGNED", + "id":str, + "adultsOnly":True, + "assignments":{"memberIds":[], + "profiles":[], + "remove":[]}} + ] + } + } + + for key in base_event: + if event.get(key) != None and not updates.get(key): + base_event[key] = event[key] + elif updates.get(key) != None: + base_event[key] = updates[key] + + data = base_event + headers = {"content-type": "application/json;charset=utf-8"} + async with self.clientsession.post(url, json=data, headers=headers) as r: + self.events_update = await r.json() + return self.events \ No newline at end of file From a3f2d80e2541167d73cd9cf3e2df1635283bedfd Mon Sep 17 00:00:00 2001 From: olizimmermann Date: Fri, 3 Feb 2023 21:45:00 +0100 Subject: [PATCH 2/2] Get Events instead of requesting dict --- spond/spond.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spond/spond.py b/spond/spond.py index 81dd618..9f23932 100644 --- a/spond/spond.py +++ b/spond/spond.py @@ -245,16 +245,14 @@ async def get_event(self, uid): return event - async def update_event(self, event_id, event: dict, updates: dict): + async def update_event(self, uid, updates: dict): """ Updates an existing event. Parameters: ---------- - event_id : str - The ID of the event -> e.g. get_events()[0]['id'] - event : dict - The original event dict, unchanged + uid : str + UID of the event. updates : dict The changes. e.g. if you want to change the description -> {'description': "New Description with changes"} @@ -265,8 +263,13 @@ async def update_event(self, event_id, event: dict, updates: dict): """ if not self.cookie: await self.login() + if not self.events: + await self.get_events() + for event in self.events: + if event["id"] == uid: + break - url = f"{self.apiurl}sponds/" + f"{event_id}" + url = f"{self.apiurl}sponds/" + f"{uid}" base_event = {"heading":str, "description": str,