From 56f15473917155a44c29e49c97cba1ef4cef159d Mon Sep 17 00:00:00 2001 From: Harmon Date: Mon, 1 Nov 2021 09:06:56 -0500 Subject: [PATCH] Add streaming example --- docs/examples.rst | 4 ++++ examples/streaming.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 examples/streaming.py 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"]) -- 2.25.1