From 7ed769b37a9fc27e36023370ad265380cbc50c52 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 17:26:44 +0100 Subject: Add list streaming --- docs/index.rst | 3 ++- mastodon/Mastodon.py | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 3dff97a..fe92636 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -585,7 +585,7 @@ will return a handle corresponding to the open connection. The connection may be closed at any time by calling the handles close() method, and the status of the connection can be verified calling is_alive() on the handle. -The streaming functions take instances of `StreamListener` as a parameter. +The streaming functions take instances of `StreamListener` as the `listener` parameter. A `CallbackStreamListener` class that allows you to specify function callbacks directly is included for convenience. @@ -593,6 +593,7 @@ directly is included for convenience. .. automethod:: Mastodon.stream_public .. automethod:: Mastodon.stream_local .. automethod:: Mastodon.stream_hashtag +.. automethod:: Mastodon.stream_list StreamListener ~~~~~~~~~~~~~~ diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 8130b2c..d8410b3 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1165,25 +1165,21 @@ class Mastodon: def stream_user(self, listener, async=False): """ Streams events that are relevant to the authorized user, i.e. home - timeline and notifications. 'listener' should be a subclass of - StreamListener which will receive callbacks for incoming events. + timeline and notifications. """ return self.__stream('/api/v1/streaming/user', listener, async=async) @api_version("1.1.0") def stream_public(self, listener, async=False): """ - Streams public events. 'listener' should be a subclass of StreamListener - which will receive callbacks for incoming events. + Streams public events. """ return self.__stream('/api/v1/streaming/public', listener, async=async) @api_version("1.1.0") def stream_local(self, listener, async=False): """ - Streams local events. 'listener' should be a subclass of StreamListener - which will receive callbacks for incoming events. - + Streams local public events. """ return self.__stream('/api/v1/streaming/public/local', listener, async=async) @@ -1191,13 +1187,21 @@ class Mastodon: def stream_hashtag(self, tag, listener, async=False): """ Stream for all public statuses for the hashtag 'tag' seen by the connected - instance. 'listener' should be a subclass of StreamListener which will receive - callbacks for incoming events. + instance. """ if tag.startswith("#"): raise MastodonIllegalArgumentError("Tag parameter should omit leading #") return self.__stream("/api/v1/streaming/hashtag?tag={}".format(tag), listener) + @api_version("2.1.0") + def stream_list(self, id, listener, async=False): + """ + Stream events for the current user, restricted to accounts on the given + list. + """ + id = self.__unpack_id(id) + return self.__stream("/api/v1/streaming/list?list={}".format(id), listener) + ### # Internal helpers, dragons probably ### -- cgit v1.2.3