Guest User

Untitled

a guest
Jan 16th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #Import the necessary methods from tweepy library
  2. from tweepy.streaming import StreamListener
  3. from tweepy import OAuthHandler
  4. from tweepy import Stream
  5.  
  6. #Variables that contains the user credentials to access Twitter API
  7. access_token = "257617341-YPmdxEAL9qNwXonEmjvWiAcdPL2U5qMEjCDhjfVi"
  8. access_token_secret = " E2cbOD3yaGyTWBeNlP6WPMMoMcMT8TodbPPEBWvTPvoOy"
  9. consumer_key = "uzIFch936Ppla0p0325Wo6Z87"
  10. consumer_secret = "JilpsLgPbRfODKJH4lvAMZWFsPB8o6UogHXXJ5SGB0nrZdSJy2"
  11.  
  12.  
  13. #This is a basic listener that just prints received tweets to stdout.
  14. class StdOutListener(StreamListener):
  15.  
  16. def on_data(self, data):
  17. print data
  18. return True
  19.  
  20. def on_error(self, status):
  21. print status
  22.  
  23.  
  24. if __name__ == '__main__':
  25.  
  26. #This handles Twitter authetification and the connection to Twitter Streaming API
  27. l = StdOutListener()
  28. auth = OAuthHandler(consumer_key, consumer_secret)
  29. auth.set_access_token(access_token, access_token_secret)
  30. stream = Stream(auth, l)
  31.  
  32. #This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
  33. stream.filter(track=['futbol'])
Add Comment
Please, Sign In to add comment