Created
January 13, 2015 05:03
-
-
Save mythmon/e25b132f659502a41a9e to your computer and use it in GitHub Desktop.
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 stream = Tw.stream('statuses/filter', { | |
locations: portland, | |
language: 'en' | |
}); | |
var fn = rateLimit(1, 5000, function(msg, username) { | |
console.log("emitting!"); | |
io.emit('stream', msg, username); | |
}); | |
io.on('connection', function(socket) { | |
console.log('new connection'); | |
socket.on('disconnect', function() { | |
console.log('user disconnected'); | |
}); | |
}); | |
// When a Tweet is recieved: | |
stream.on('tweet', function(tweet) { | |
if (tweet.geo) { | |
if (parseFloat(tweet.geo.coordinates[0]) < portland[3] && parseFloat(tweet.geo.coordinates[0]) > portland[1]) { | |
if (parseFloat(tweet.geo.coordinates[1]) < portland[2] && parseFloat(tweet.geo.coordinates[1]) > portland[0]) { | |
// Makes a link the Tweet clickable | |
console.log("tweet"); | |
tweetQueue.push(tweet); | |
if(tweetQueue.length >0){ | |
rateLimitEmit(); | |
} | |
} | |
} | |
} | |
}); | |
var rateLimitEmit = function() { | |
console.log("rateLimited Emit called"); | |
var turl = tweetQueue[0].text.match(/(http|https|ftp):\/\/[^\s]*/i); | |
if (turl !== null) { | |
turl = tweetQueue[0].text.replace(turl[0], '<a href="' + turl[0] + '" target="new">' + turl[0] + '</a>'); | |
} else { | |
turl = tweetQueue[0].text; | |
console.log("emitting tweet"); | |
//call rate-limited function. | |
fn(turl, tweetQueue[0].user.screen_name); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment