Created
September 24, 2013 21:26
-
-
Save rgrwkmn/6691495 to your computer and use it in GitHub Desktop.
Node script using ntwitter and cli-color to log streaming tweets into your terminal. Enter your own API keys and secrets, npm install ntwitter cli-color; node twitter-stream.js;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var twitter = require('ntwitter'); | |
| var clc = require('cli-color'); | |
| var twit = new twitter({ | |
| consumer_key: 'key', | |
| consumer_secret: 'secret', | |
| access_token_key: 'key', | |
| access_token_secret: 'secret' | |
| }); | |
| twit | |
| .verifyCredentials(function (err, data) { | |
| if (err) { | |
| throw new Error(err); | |
| } | |
| }); | |
| // Chicago | |
| //{'locations':'-87.87,41.7,-87.48,42.06'} | |
| // NY and San Fran? Came from the example | |
| //{'locations':'-122.75,36.8,-121.75,37.8,-74,40,-73,41'} | |
| twit.stream('statuses/filter', {'locations':'-87.87,41.7,-87.48,42.06'}, function(stream) { | |
| stream.on('data', function (data) { | |
| var orange = clc.xterm(214); | |
| var blue = clc.xterm(45); | |
| var text = data.text | |
| .replace(/(\@[^\s]+)/g, orange('$1')) | |
| .replace(/(\#[^\s]+)/g, blue('$1')); | |
| console.log(clc.green(data.user.screen_name)+' -', text); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment