]>
jfr.im git - z_archive/twitter.git/blob - twitter/stream_example.py
2 Example program for the Stream API. This prints public status messages
3 from the "sample" stream as fast as possible.
7 twitter-stream-example <username> <password>
11 from __future__
import print_function
15 from .stream
import TwitterStream
16 from .auth
import UserPassAuth
17 from .util
import printNicely
19 def main(args
=sys
.argv
[1:]):
24 # When using twitter stream you must authorize. UserPass or OAuth.
25 stream
= TwitterStream(auth
=UserPassAuth(args
[0], args
[1]))
27 # Iterate over the sample stream.
28 tweet_iter
= stream
.statuses
.sample()
29 for tweet
in tweet_iter
:
30 # You must test that your tweet has text. It might be a delete
33 printNicely(tweet
['text'])