Skip to content

Instantly share code, notes, and snippets.

@ngpestelos
Forked from mneedham/gist:339579
Created September 3, 2010 00:46
Show Gist options
  • Save ngpestelos/563208 to your computer and use it in GitHub Desktop.
Save ngpestelos/563208 to your computer and use it in GitHub Desktop.
var sys = require('sys'), http = require('http'), twitter = require('./twitter'), couch = require("./node-couch");
Array.prototype.each = function(fn) {
for (var i = 0; i < this.length; i++) {
var item = this[i];
fn.call(null, item);
}
return this;
};
var couchDB = couch.CouchDB.db("twitter", "5984", "127.0.0.1");
var server = http.createServer(function (req, res) {
couchDB.view("application/sort-by-id", {
descending : true,
success : function(response) {
twitter.query("friends_timeline", {
username : "username",
password : "password",
since_id : response.rows[0].value.id,
count: 200,
callback : function(tweets) {
tweets.each(function(tweet) {
couchDB.saveDoc(tweet, {
success : function(doc) {
sys.log("Document " + doc._id + " successfully saved")
},
error : function() {
sys.log("Document failed to save");
}
});
});
}
});
},
error : function() {
sys.log("Failed to retrieve documents");
}
});
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('OK');
res.close();
});
server.listen(8001);
var ping = http.createClient(8001, "127.0.0.1");
setInterval(function() {
var request = ping.request("GET", "/");
request.close();
}, 60000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment