GET with node
This file contains 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
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