Skip to content

Instantly share code, notes, and snippets.

@ntanya
Created June 8, 2012 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntanya/2898381 to your computer and use it in GitHub Desktop.
Save ntanya/2898381 to your computer and use it in GitHub Desktop.
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