Created
July 11, 2011 17:14
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
var async = require("async"), | |
github = new (require("github").GitHubApi)(), | |
users = github.getUserApi(), | |
names = require("./femalenames").slice(0, 50), | |
cradle = require("cradle"), | |
fs = require("fs"); | |
var toFollow = []; | |
function dateAgo(daysAgo) { | |
daysAgo = daysAgo || 0; | |
var dayMs = 1000 * 60 * 60 * 24; | |
return new Date(Date.now() - (dayMs * daysAgo)); | |
} | |
function isFirstName(name, first) { | |
return name.toLowerCase().indexOf(first.toLowerCase()) == 0; | |
} | |
async.forEach(names, function(name, done) { | |
users.search(name, function(err, users) { | |
if (err) throw "GitHub API error " + JSON.stringify(err); | |
users.forEach(function(user) { | |
if (isFirstName(user.name, name) | |
&& user.public_repo_count > 5 | |
&& user.followers_count > 10 | |
&& (new Date(user.pushed) > dateAgo(60))) | |
toFollow.push({ | |
name: user.name, | |
username: user.username, | |
followers: user.followers_count, | |
repos: user.public_repo_count, | |
language: user.language | |
}); | |
}); | |
done(); | |
}); | |
}, function (err) { | |
if (err) throw err; | |
console.log("found " + toFollow.length + " GitHub users"); | |
var client = new cradle.Connection("http://harth.iriscouch.com"); | |
var db = client.database("github"); | |
toFollow = toFollow.map(function(user) { | |
user._id = user.username; | |
return user; | |
}) | |
db.save(toFollow, function(err, resp) { | |
if (err) throw "Error saving to CouchDB " + err; | |
console.log("Saved names to db 'github'"); | |
}); | |
fs.writeFileSync("output.json", JSON.stringify(toFollow)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't let this fall into the wrong hands!