Skip to content

Instantly share code, notes, and snippets.

@sAbakumoff
Last active September 26, 2016 13:31
Show Gist options
  • Save sAbakumoff/88b5593e6bb1dcd2b85993668eab1758 to your computer and use it in GitHub Desktop.
Save sAbakumoff/88b5593e6bb1dcd2b85993668eab1758 to your computer and use it in GitHub Desktop.
var Twitter = require('twitter');
var client = new Twitter(/*pass auth keys*/);
function startTracking(topic){
var isTweet = obj => obj && typeof obj.id_str === 'string' &&
typeof obj.text === 'string' && obj.place &&
obj.place.country_code === "US" && obj.place.place_type === "city";
var handleTweet = tweet => {
if(isTweet(tweet)){
topic.publish({
data : tweet,
attributes : {created_at : tweet.created_at}
}, function(err, messageIds, apiResponse){
if(err)
return console.log("Error publishing : %s", err);
console.log("Message %s published", messageIds)
});
}
}
client.stream('statuses/filter', {track: 'Trump,Hillary,Clinton,debate'}, function(stream) {
stream.on('data', handleTweet);
stream.on('error', console.log);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment