TweetPipe
Connect to Twitter's Streaming API via Node.js Streams (using EventStreams) https://github.com/peeinears/tweet-pipe
:)
- Uses Node Streams
- With the help of EventStream
- and Request (which also uses EventStream)
- This means you can
pipe()
stuff around, which is really great - Can pull down and deflate gzipped data (and does so by default)
- Inspiration (and some borrowed logic) from ntwitter
:(
- No tests
- Site streams currently unsupported
- Lacking in error handling
Put some tweets in your pipe and do stuff with them
Basic usage
Setup
var TweetPipe = ;var tp =consumer_key: 'yourconsumerkey'consumer_secret: 'yourconsumersecret'token: 'youraccesstoken'token_secret: 'youraccesstokensecret';
Streamin'
tp.stream(method [, params] [, data_events] [, callback(stream)])
tp; // returns a Stream that emits tweet JSON
That won't really do anything, but from there you can pipe the tweets into other streams that do stuff:
tp;
With params
var params ='track': 'ball' 'rim' 'john''locations': '-122.75,36.8,-121.75,37.8' '-74,40,-73,41' // SF and NY'follow': 'justinbieber' 'nodejs';tp; // will emit tweets that match any one of the params
With a callback
tp;
'data'
Change what gets emitted as By default, tp.stream()
will only pipe out tweets (as JSON).
You can change this so that other message types are emitted as 'data'
.
// pipe out 'delete' and 'scrub_geo' messages as welltp;// pipe out all message typestp;// don't pipe anything outtp;// pipe out only tweet texttp;
Supported events
Refer to: https://dev.twitter.com/docs/streaming-apis/messages
'tweet'
, 'delete'
, 'limit'
, 'scrub_geo'
, 'status_withheld'
, 'user_withheld'
, 'friends'
, 'event'
'all'
emits data chunks of all types
Raw streams and convenience methods
You can also access the raw, [un-deflated,] unparsed stream with tp.raw_stream(method, params, callback)
.
Note that the callback here is on the Request
object -- the above events are not emitted.
If you're piping this stream elsewhere you can use
tp.unzip()
to deflate gzipped streams and
tp.parse()
to convert the stream into JSON.
tp.stringify()
is also available and can be useful with tp.stream()
.
tp// to JSON; // woo, back to a string!
Example
Track the popularity of various Mexican cuisine for one minute:
var TweetPipe = ;var oauth =consumer_key: 'yourconsumerkey'consumer_secret: 'yourconsumersecret'token: 'youraccesstoken'token_secret: 'youraccesstokensecret';var tp = oauth;var tacos = burritos = enchiladas = 0;var params = track: 'taco' 'burrito' 'enchilada' ;tp; // tweet text piped to stdout
License
MIT