Skip to content
Snippets Groups Projects
Commit 2eac44f6 authored by matt01671's avatar matt01671
Browse files

added stream

parent 9739efcb
No related branches found
No related tags found
No related merge requests found
...@@ -3,11 +3,6 @@ import tweepy ...@@ -3,11 +3,6 @@ import tweepy
consumer_key = consumer_key =
consumer_secret = consumer_secret =
# OAuthHandler instance OAuth 2 Authentication
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth)
def get_tweets(query, count = 300): def get_tweets(query, count = 300):
# empty list to store parsed tweets # empty list to store parsed tweets
...@@ -30,6 +25,12 @@ def get_tweets(query, count = 300): ...@@ -30,6 +25,12 @@ def get_tweets(query, count = 300):
t1.write(line+"\n") t1.write(line+"\n")
return tweets return tweets
def main():
# OAuthHandler instance OAuth 2 Authentication
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth)
# creating object of TwitterClient Class # creating object of TwitterClient Class
# calling function to get tweets # calling function to get tweets
tweets = get_tweets(query =text, count = 20000) tweets = get_tweets(query =text, count = 20000)
\ No newline at end of file
import tweepy
consumer_key =
consumer_secret =
#override tweepy.StreamListener to add logic to on_status
class MyStreamListener(tweepy.StreamListener):
def on_status(self, status):
print(status.text)
def on_error(self, status_code):
if status_code == 420:
#returning False in on_error disconnects the stream
return False
# returning non-False reconnects the stream, with backoff.
def main():
# OAuthHandler instance OAuth 2 Authentication
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth)
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener=myStreamListener)
myStream.filter(track=['python'])
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment