Created
March 16, 2019 22:39
-
-
Save arriqaaq/1cc0cfd3d90bacbfe59c5dbbf14166d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Import the necessary methods from tweepy library | |
from tweepy.streaming import StreamListener | |
from tweepy import OAuthHandler | |
from tweepy import Stream | |
access_token="ENTER YOUR ACCESS TOKEN" | |
access_token_secret="ENTER YOUR ACCESS TOKEN SECRET" | |
consumer_key="ENTER YOUR API KEY" | |
consumer_secret="ENTER YOUR API SECRET" | |
class Listener(StreamListener): | |
def on_data(self, data): | |
print data | |
return True | |
def on_error(self, status): | |
print status | |
if __name__ == '__main__': | |
#This handles Twitter authetification and the connection to Twitter Streaming API | |
twitter_data = Listener() | |
auth = OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
stream = Stream(auth, twitter_data) | |
#This line filter Twitter Streams to capture data by the keywords: 'manutd', 'barca' | |
stream.filter(track=['manutd', 'barca']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment