Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added update_event function #56

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions spond/spond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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