aboutsummaryrefslogtreecommitdiffstats
path: root/poll.py
diff options
context:
space:
mode:
authorla-ninpre <leobrekalini@gmail.com>2022-02-14 13:13:13 +0300
committerla-ninpre <leobrekalini@gmail.com>2022-02-14 13:14:22 +0300
commit0290237358c3aaae4dd35468525a2f3685e959ef (patch)
tree04ddbaa68426e06eeb550ccf5b27d5a1787253de /poll.py
downloadpleroma_announce-0290237358c3aaae4dd35468525a2f3685e959ef.tar.gz
pleroma_announce-0290237358c3aaae4dd35468525a2f3685e959ef.zip
initial commitHEADv0.1main
Diffstat (limited to 'poll.py')
-rw-r--r--poll.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/poll.py b/poll.py
new file mode 100644
index 0000000..4d58dea
--- /dev/null
+++ b/poll.py
@@ -0,0 +1,71 @@
+"""poll wrapper class"""
+
+import datetime
+
+class PleromaPoll:
+ """
+ wrapper class for handling polls
+ """
+ def __init__(self,
+ options: list[str],
+ expires_in: datetime.timedelta,
+ multiple: bool = None,
+ hide_totals: bool = None):
+ self._options = options
+ self._expires_in = expires_in.total_seconds()
+ self._multiple = multiple
+ self._hide_totals = hide_totals
+
+ @classmethod
+ def from_response(cls, data: dict):
+ """
+ alternative constructor to create object from response of a server
+
+ as the app is used to only view scheduled posts, this constructor doesn't
+ retain information about vote counts.
+ """
+ return cls(expires_in=datetime.datetime.fromisoformat(data["expires_in"]),
+ multiple=data["multiple"],
+ options=[i["title"] for i in data["options"]])
+
+ @property
+ def options(self):
+ """
+ a list of strings, which are options for poll
+ """
+ return self._options
+
+ @property
+ def expires_in(self):
+ """
+ timedelta, which represents time in which poll will expire
+ """
+ return self._expires_in
+
+ @property
+ def multiple(self):
+ """
+ boolean flag, True if poll allows multiple choices
+ """
+ return self._multiple
+
+ @multiple.setter
+ def multiple(self, flag: bool):
+ self._multiple = flag
+
+ @property
+ def hide_totals(self):
+ """
+ boolean flag, True if counts are hidden until poll ends
+ """
+ return self._hide_totals
+
+ @hide_totals.setter
+ def hide_totals(self, flag: bool):
+ self._hide_totals = flag
+
+ def __repr__(self):
+ return f"PleromaPoll(options={self._options},\
+expires_in={self._expires_in},\
+multiple={self._multiple},\
+hide_totals={self._hide_totals})"