]> projects.mako.cc - twitter-api-cdsw-solutions/blob - twitter-stream1.py
e94422dd0f8dc43b3c99258755aa429cea3a17a6
[twitter-api-cdsw-solutions] / twitter-stream1.py
1 import encoding_fix
2 import tweepy
3 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
4
5 auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
6 auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
7
8 api = tweepy.API(auth)
9
10 class StreamListener(tweepy.StreamListener):
11     def on_status(self, tweet):
12         print(tweet.author.screen_name + "\t" + tweet.text)
13
14     def on_error(self, status_code):
15         print('Error: ' + repr(status_code))
16         return False
17
18 l = StreamListener()
19 streamer = tweepy.Stream(auth=auth, listener=l)
20
21 streamer.sample()

Benjamin Mako Hill || Want to submit a patch?