Created
April 15, 2015 16:57
-
-
Save genecyber/f493a01d460618acd79a to your computer and use it in GitHub Desktop.
read insight email store database
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 levelup = require('levelup') | |
var db = levelup('./') | |
var collection = new Array() | |
var newCollection = new Array() | |
var sort_by = function(field, reverse, primer){ | |
var key = primer ? | |
function(x) {return primer(x[field])} : | |
function(x) {return x[field]}; | |
reverse = !reverse ? 1 : -1; | |
return function (a, b) { | |
return a = key(a), b = key(b), reverse * ((a > b) - (b > a)); | |
} | |
} | |
db.createReadStream() | |
.on('data', function(data){ | |
if (data.key.indexOf("pending-") > -1) { | |
var email = data.key.replace('pending-','') | |
//var date = new Date(JSON.parse(data.value).created*1000) | |
var json = {email : email.toString(), date : JSON.parse(data.value).created} | |
collection.push(json) | |
} | |
}) | |
.on('close', function () { | |
collection.sort(sort_by('date',false,parseInt)) | |
for (item in collection) { | |
var date = new Date(collection[item].date*1000) | |
var email = collection[item].email | |
newCollection.push({email: email, date: date}) | |
} | |
console.log(JSON.stringify(newCollection)) | |
db.close() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment