diff --git a/spond/spond.py b/spond/spond.py index 5808469..95e6d52 100644 --- a/spond/spond.py +++ b/spond/spond.py @@ -241,3 +241,76 @@ async def get_event(self, uid): for event in self.events: if event["id"] == uid: return event + + + async def update_event(self, uid, updates: dict): + """ + Updates an existing event. + + Parameters: + ---------- + uid : str + UID of the event. + 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() + if not self.events: + await self.get_events() + for event in self.events: + if event["id"] == uid: + break + + url = f"{self.apiurl}sponds/" + f"{uid}" + + 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