Skip to content

Instantly share code, notes, and snippets.

@david-hodgetts
Created March 21, 2014 21:33
Show Gist options
  • Save david-hodgetts/9696970 to your computer and use it in GitHub Desktop.
Save david-hodgetts/9696970 to your computer and use it in GitHub Desktop.
// import libraries
var Twit = require('twit'),
inits = require('./inits');
dbName = inits.dbName,
db = require('nano')("http://localhost:5984/" + dbName);
// instantiate twitter connection
var T = new Twit({
consumer_key: inits.api_key,
consumer_secret: inits.api_secret,
access_token: inits.access_token,
access_token_secret: inits.access_token_secret
});
// count insertions in couchDB
var count = 0;
// function called after a db insertion call to couchDB
// used to handle result of operation
// errors are logged to std out but are otherwise ignored
var insertCallback = function (err, body){
if (err){
console.log("error inserting");
console.log(err);
}else{
console.log("inserting tweet " + count);
count +=1;
}
};
// filter the public stream for tweets containing #geneve
var stream = T.stream('statuses/filter', { track: '#geneve' });
stream.on('tweet', function (tweet) {
// this is called when a new tweet is notified
// we insert the tweet into couchdb
db.insert(tweet, tweet.id_str, insertCallback);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment