]> projects.mako.cc - twitter-api-cdsw-solutions/blob - twitter-stream-raw1.py
b6ea13bf321a8753ef3968924a32925bc7e4a4bf
[twitter-api-cdsw-solutions] / twitter-stream-raw1.py
1 import encoding_fix
2 import json
3 import tweepy
4 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
5
6 auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
7 auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
8
9 api = tweepy.API(auth, parser=tweepy.parsers.RawParser())
10
11 @classmethod                    
12 def parse(cls, api, raw):
13     status = cls.first_parse(api, raw)
14     setattr(status, 'json', json.dumps(raw))
15     return status
16
17 tweepy.models.Status.first_parse = tweepy.models.Status.parse
18 tweepy.models.Status.parse = parse
19
20 class StreamListener(tweepy.StreamListener):
21     def on_status(self, tweet):
22         print(tweet.json)
23
24     def on_error(self, status_code):
25         print('Error: ' + repr(status_code))
26         return False
27
28 l = StreamListener()
29 streamer = tweepy.Stream(auth=auth, listener=l)
30
31 streamer.sample()

Benjamin Mako Hill || Want to submit a patch?