Last active
September 26, 2016 13:31
-
-
Save sAbakumoff/88b5593e6bb1dcd2b85993668eab1758 to your computer and use it in GitHub Desktop.
This file contains 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('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