Skip to content

Instantly share code, notes, and snippets.

@konsumer
Created July 1, 2014 03:32
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 konsumer/ef1f4aae96cb750f30a8 to your computer and use it in GitHub Desktop.
Save konsumer/ef1f4aae96cb750f30a8 to your computer and use it in GitHub Desktop.
save these 2 files, run `npm install`
{
"name": "testdir",
"version": "0.0.0",
"main": "index.js",
"dependencies": {
"randopeep": "^0.2.0",
"request": "^2.36.0"
}
}
var randopeep = require('randopeep'),
request = require('request');
var newguy = {
gender: 'male',
origin: 'netrunner'
};
var options = Object.create(newguy);
options.prefix=false;
newguy.name = randopeep.name(options);
newguy.email = randopeep.internet.email(newguy.name);
newguy.ip = randopeep.internet.ip();
function randomLocation(cb){
var ip = randopeep.internet.ip();
request('http://freegeoip.net/json/' + ip, function (er, res, body) {
if (er) return cb(er);
var info = JSON.parse(body);
if (!info || !info.zipcode) return randomLocation(cb);
cb(null, info);
});
}
randomLocation(function(er, info){
if (er) return console.log(er);
newguy.ip = info.ip;
newguy.area_code = info.area_code
delete info.ip;
delete info.metro_code;
delete info.area_code;
newguy.address = info;
newguy.address.street = randopeep.address.streetAddress();
console.log(newguy);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment