Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Last active January 3, 2016 19:29
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 calvinmetcalf/8509031 to your computer and use it in GitHub Desktop.
Save calvinmetcalf/8509031 to your computer and use it in GitHub Desktop.
co(function*(){
var i2 = -1;
var len2 = names.length;
var db = yield PouchDB.bind(null,'names');
db.replicate.to('http://127.0.0.1:5984/cases',{continuous:true});
var out = [];
while(++i2<len2){
let which = names[i2];
let whichName = which.split("_").join(" ");
console.log(whichName);
out[i2] = yield co(function*(){
var baseDir = './'+which;
var inDir = baseDir + "/documents";
var files = yield fs.readdir.bind(fs, inDir);
var len = files.length;
var i = -1;
while(++i<len){
let file = yield fs.readFile.bind(fs,inDir+'/'+files[i],{encoding:'utf8'});
let json = yield parseXML(file);
cleanUpJson(json);//actually just omited code
try{
yield db.put.bind(db,json);
}catch(e){
//handle error
//omited
}
}
return 'done '+i+" for"+whichName;
});
}
return out;
})(function(err,done){
console.log(err, done);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment