Skip to content

Instantly share code, notes, and snippets.

@ntanya
Created Jun 8, 2012
Embed
What would you like to do?
GET with node
response.on('end', function(){
var dataObj = JSON.parse(completeResponse);
var saveObj = {
id: dataObj["id"],
created_at: dataObj["created_at"],
description: dataObj["description"],
followers_count: dataObj["followers_count"],
friends_count: dataObj["friends_count"],
location: dataObj["location"],
name: dataObj["name"]
};
//console.log("screen name: " + dataObj["screen_name"]);
// Only save people with more than 1000 followers
if(dataObj["followers_count"] > 1000){
dbsave(saveObj);
}
res.send('Saved Twitter user: ' + dataObj["screen_name"] + ", with number of followers: " + dataObj["followers_count"]);
});
// Saving data
var mongostr = "mongodb://localhost/dataintel";
var database = null;
function dbsave(data)
{
mongo.connect(mongostr, {}, function(error, db)
{
database = db;
var mycoll = database.collection("leads");
mycoll.insert(data, function(){console.log("saved");});
database.addListener("error", function(error){
console.log("Error connecting to MongoLab");
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment