Created
March 21, 2014 21:33
-
-
Save david-hodgetts/9696970 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
// 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