Skip to content

Instantly share code, notes, and snippets.

@davidjrice
Created April 15, 2010 22:41
Show Gist options
  • Save davidjrice/367761 to your computer and use it in GitHub Desktop.
Save davidjrice/367761 to your computer and use it in GitHub Desktop.
var twitterStatus = "not-started";
function monitorTwitter() {
puts('> monitoring twitter stream ');
var twit = new TwitterNode({
user: 'xxx',
password: 'xxx',
track: ['somehashtag']
});
twitterStatus = "online";
twit.headers['User-Agent'] = 'whatever'
twit
.addListener('tweet', function(tweet) {
puts(sys.inspect(tweet))
})
.addListener('limit', function(limit) {
puts("LIMIT: " + sys.inspect(limit))
})
.addListener('delete', function(del) {
puts("DELETE: " + sys.inspect(del))
})
.addListener('close', function(resp) {
puts("> RECEIVED CLOSE EVENT... " + resp.statusCode);
twitterStatus="offline"
monitorTwitter();
})
.stream()
}
function monitorTwitterMonitor() {
setTimeout(function() {
if(twitterStatus=="offline") {
puts("> twitter feed is offline, restarting");
monitorTwitter();
} else {
puts("> twitter feed is fine, carry on");
monitorTwitterMonitor();
}
}, 60*1000);
}
monitorTwitter();
monitorTwitterMonitor();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment