convert files to json db

This commit is contained in:
AJ ONeal 2018-08-05 05:48:31 +00:00
parent e4534d6076
commit 5940d4bd28
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
'use strict';
var fs = require('fs');
var path = require('path');
var basedir = path.join(__dirname, 'emails');
var files = fs.readdirSync(basedir)
var emails = {};
files.forEach(function (fname) {
var fpath = path.join(basedir, fname);
var data;
var email;
var iat;
if (!/\.data$/.test(fname)) {
return;
}
data = JSON.parse(fs.readFileSync(fpath));
email = fname.replace('\.' + data.domains.join('') + '\.data', '');
if (data.iat) {
iat = new Date(data.iat).toISOString();
}
if (!emails[email]) {
emails[email] = {
domains: []
, ports: []
, nodes: [ { issuedAt: iat, scheme: 'mailto', type: 'email', name: email } ]
, jtis: []
};
}
emails[email].jtis.push(data.id);
data.domains.forEach(function (d) {
emails[email].domains.push({ issuedAt: iat, name: d });
});
data.ports.forEach(function (p) {
emails[email].ports.push({ issuedAt: iat, number: p });
});
});
console.log('[\n' + Object.keys(emails).map(function (k) { return JSON.stringify(emails[k]); }).join(',\n') + '\n]');