Add streaming example
authorHarmon <Harmon758@gmail.com>
Mon, 1 Nov 2021 14:06:56 +0000 (09:06 -0500)
committerHarmon <Harmon758@gmail.com>
Mon, 1 Nov 2021 14:06:56 +0000 (09:06 -0500)
docs/examples.rst
examples/streaming.py [new file with mode: 0644]

index 5adefcc75b3e6a42ea6289c2ccb0d9bf70ea481e..541a3ca9bb6dc9a70f02ab14e4d874082d3a69a4 100644 (file)
@@ -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 (file)
index 0000000..1349c3a
--- /dev/null
@@ -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"])