Last active
January 3, 2016 19:29
-
-
Save calvinmetcalf/8509031 to your computer and use it in GitHub Desktop.
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
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