From 5852f9ae905136082804677063f62dbe793af0eb Mon Sep 17 00:00:00 2001 From: amaurylekens Date: Sat, 22 Oct 2022 00:37:57 +0200 Subject: [PATCH 1/2] Add method to write a post --- spond/spond.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spond/spond.py b/spond/spond.py index fbc4975..e40d5d0 100644 --- a/spond/spond.py +++ b/spond/spond.py @@ -212,3 +212,43 @@ async def get_event(self, uid): for event in self.events: if event['id'] == uid: return event + + async def write_post(self, group_id: str, title: str, body: str, + comment_disabled: bool) -> Dict[str, Any]: + """ + Write post on the main page of a group. + + Parameters + ---------- + group_id : str + Id of the group. + title: str + Title of the post. + body: str + Body of the post. + comment_disabled: bool. + Bool to say if the comments on the post are disabled or not. + + Returns + ------- + dict + Result of writing the post. + """ + if not self.cookie: + await self.login() + url = self.apiurl + "posts" + + data = { + "type": "PLAIN", + "groupId": group_id, + "visibility": "ALL", + "commentsDisabled": comment_disabled, + "attachments": [], + "title": title, + "body": body, + "media": [] + } + + headers = {'auth': self.auth} + r = await self.clientsession.post(url, json=data, headers=headers) + return await r.json() From 970764edca2a557efa18211c6c519ecb486a1d67 Mon Sep 17 00:00:00 2001 From: amaurylekens Date: Sat, 22 Oct 2022 00:59:01 +0200 Subject: [PATCH 2/2] Add method to write a poll --- spond/spond.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/spond/spond.py b/spond/spond.py index e40d5d0..b095876 100644 --- a/spond/spond.py +++ b/spond/spond.py @@ -226,7 +226,7 @@ async def write_post(self, group_id: str, title: str, body: str, Title of the post. body: str Body of the post. - comment_disabled: bool. + comment_disabled: bool Bool to say if the comments on the post are disabled or not. Returns @@ -252,3 +252,59 @@ async def write_post(self, group_id: str, title: str, body: str, headers = {'auth': self.auth} r = await self.clientsession.post(url, json=data, headers=headers) return await r.json() + + async def write_poll(self, group_id: str, title: str, description: str, + comment_disabled: bool, options: List[str], + hide_votes: bool, multiple_choices: bool, due_datetime: datetime) -> Dict[str, Any]: + """ + Write poll on the main page of a group. + + Parameters + ---------- + group_id : str + Id of the group. + title: str + Title of the poll. + description: str + Description of the poll. + comment_disabled: bool + Bool to say if the comments on the poll are disabled or not. + options: list + List of options. + hide_votes: bool + Bool to say if the votes are hided or not. + multiple_choices: bool + Bool to say if multiple choices are allowed or not. + due_datetime: datetime + Deadline to complete the poll. + + Returns + ------- + dict + Result of writing the poll. + """ + if not self.cookie: + await self.login() + url = self.apiurl + "posts" + + data = { + "type": "POLL", + "groupId": group_id, + "visibility": "ALL", + "commentsDisabled": comment_disabled, + "attachments": [], + "poll": { + "question": title, + "description": description, + "options": [{"text": option} for option in options], + "hideVotes": hide_votes, + "dueBy": due_datetime.strftime('%Y-%m-%dT%H:%M:%S.000Z'), + "multipleChoice": multiple_choices, + "commentsDisabled": comment_disabled, + "type": "TEXT" + } + } + + headers = {'auth': self.auth} + r = await self.clientsession.post(url, json=data, headers=headers) + return await r.json()