From 39f1ee8889461917a797b1e785dd2411c8d3b676 Mon Sep 17 00:00:00 2001 From: halcy Date: Sun, 23 Apr 2023 19:19:53 +0300 Subject: [PATCH] Add support for public/remote stream --- CHANGELOG.rst | 1 + mastodon/streaming_endpoints.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 80e5182..105bf77 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ v1.8.1 (in progress) * Add readme to PyPi page (thanks hugovk) * Fix `list_accounts` to actually include request parameters (thanks leoncowle) * Small formatting changes (thanks amaargiru) +* Add link to examples to docs and readme. v1.8.0 ------ diff --git a/mastodon/streaming_endpoints.py b/mastodon/streaming_endpoints.py index fc705e6..413e898 100644 --- a/mastodon/streaming_endpoints.py +++ b/mastodon/streaming_endpoints.py @@ -20,18 +20,28 @@ class Mastodon(Internals): return self.__stream('/api/v1/streaming/user', listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) @api_version("1.1.0", "1.4.2", _DICT_VERSION_STATUS) - def stream_public(self, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC): + def stream_public(self, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC, local=False, remote=False): """ Streams public events. """ - return self.__stream('/api/v1/streaming/public', listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) + base = '/api/v1/streaming/public' + if local: + base += '/local' + if remote: + if local: + raise MastodonIllegalArgumentError("Cannot pass both local and remote - use either one or the other.") + base += '/remote' + return self.__stream(base listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) @api_version("1.1.0", "1.4.2", _DICT_VERSION_STATUS) def stream_local(self, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC): """ Streams local public events. + + This function is deprecated. Please use :ref:`stream_public() ` with parameter `local` set to True instead. """ - return self.__stream('/api/v1/streaming/public/local', listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) + #return self.__stream('/api/v1/streaming/public/local', listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) + return self.stream_public(listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec, local=True) @api_version("1.1.0", "1.4.2", _DICT_VERSION_STATUS) def stream_hashtag(self, tag, listener, local=False, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC):