Skip to content

Commit

Permalink
Merge pull request #56 from olizimmermann/main
Browse files Browse the repository at this point in the history
added update_event function
  • Loading branch information
Olen authored Feb 10, 2023
2 parents 9d08695 + a3f2d80 commit f0c90d9
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions spond/spond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f0c90d9

Please sign in to comment.