Skip to content

Instantly share code, notes, and snippets.

@konsumer
Created July 7, 2014 01: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 konsumer/6d24b8cdd3f353ddc0fa to your computer and use it in GitHub Desktop.
Save konsumer/6d24b8cdd3f353ddc0fa to your computer and use it in GitHub Desktop.
var db = require('./db'),
readline = require('readline'),
path = require('path'),
fs = require('fs'),
poolr = require('poolr').createPool,
couchPool = poolr(2, db);
var types = {
'first':'facebook-firstnames-withcount',
'last':'facebook-lastnames-withcount',
'full':'facebook-names-unique'
};
// process a text file, insert in couch
function processFile(type){
var fname = path.join('data', types[type] + '.txt');
var rd = readline.createInterface({
input: fs.createReadStream(fname),
output: process.stdout,
terminal: false
});
rd.on('line', function(line) {
rd.pause();
var record = { type: type };
if (type == 'full'){
record.name = line.trim().split(' ');
}else{
var i = line.trim().split(' ');
record.name = i[1].trim();
record.count = Number(i[0]);
}
couchPool.addTask(db.save, record, function(er, res) {
if (er) console.log('Error: ', er);
console.log(res);
rd.resume();
});
});
}
for (type in types){
processFile(type);
}
// views for looking things up
db.save('_design/views', require('./views'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment