Guest User

Untitled

a guest
Jun 19th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 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 = "Enter the token"
  8. access_token_secret = "Enter the token secret"
  9. consumer_key = "Enter API key"
  10. consumer_secret = "Enter API secret"
  11.  
  12.  
  13. #This is a basic listener that just prints received tweets to stdout.
  14.  
  15. MAX_NUM_TWEETS = 50000
  16. class StdOutListener(StreamListener):
  17. def __init__(self):
  18. self.count = 0
  19.  
  20. def on_data(self, data):
  21. self.count += 1
  22. print data
  23. if self.count > MAX_NUM_TWEETS:
  24. return False
  25. return True
  26.  
  27. def on_error(self, status):
  28. print status
  29.  
  30.  
  31. if __name__ == '__main__':
  32.  
  33. #This handles Twitter authetification and the connection to Twitter Streaming API
  34. l = StdOutListener()
  35. auth = OAuthHandler(consumer_key, consumer_secret)
  36. auth.set_access_token(access_token, access_token_secret)
  37. stream = Stream(auth, l)
  38.  
  39. #This line filter Twitter Streams to capture data by the keywords: 'FIFA', 'World', 'Cup','football' etc.
  40. # stream.filter(track=['FIFA', 'World','Cup','football', 'FIFA World Cup','#FIFA2018','WorldCup','#WorldCup2018','#FifaWorldCup','#FIFAWorldCup','RUSKSA','#RUSKSA','prediction','win','#FIFA'])
  41. stream.filter(track=['#FIFA','#WorldCup'])
Add Comment
Please, Sign In to add comment