From: Harmon Date: Mon, 1 Nov 2021 14:06:56 +0000 (-0500) Subject: Add streaming example X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=56f15473917155a44c29e49c97cba1ef4cef159d;p=tweepy.git Add streaming example --- diff --git a/docs/examples.rst b/docs/examples.rst index 5adefcc..541a3ca 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -25,3 +25,7 @@ Examples .. tab:: Handle Rate Limits .. literalinclude:: ../examples/rate_limit_handling.py + + .. tab:: Streaming + + .. literalinclude:: ../examples/streaming.py diff --git a/examples/streaming.py b/examples/streaming.py new file mode 100644 index 0000000..1349c3a --- /dev/null +++ b/examples/streaming.py @@ -0,0 +1,22 @@ +import tweepy + + +consumer_key = "" +consumer_secret = "" +access_token = "" +access_token_secret = "" + +# Subclass Stream to print IDs of Tweets received +class IDPrinter(tweepy.Stream): + + def on_status(self, status): + print(status.id) + +# Initialize instance of the subclass +printer = IDPrinter( + consumer_key, consumer_secret, + access_token, access_token_secret +) + +# Filter realtime Tweets by keyword +printer.filter(track=["Twitter"])