Last active
April 3, 2019 13:49
-
-
Save petercunha/529b3f2ecd9572523b3d55ae7474ed40 to your computer and use it in GitHub Desktop.
Script to aid in parsing Collection #1
This file contains hidden or 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
// Reads in email:password file "input.txt" and converts it into JSON "output.json" for easy MongoDB import. | |
const readline = require('readline') | |
const fs = require('fs') | |
const writeStream = fs.createWriteStream('output.json') | |
let line_no = 0 | |
let invalid = 0 | |
let rl = readline.createInterface({ | |
input: fs.createReadStream('input.txt') | |
}) | |
setInterval(() => { | |
console.log( | |
'inserted ' + | |
Number((100 * line_no) / 10000000.0).toFixed(2) + /* Replace "10000000" with your number of lines" */ | |
'% with ' + | |
Number((100 * invalid) / line_no).toFixed(2) + | |
'% invalid' | |
) | |
}, 500) | |
rl.on('line', line => { | |
try { | |
var i = line.indexOf(':') | |
var splits = [line.slice(0, i), line.slice(i + 1)] | |
var data = JSON.stringify({ | |
email: splits[0], | |
password: splits[1] | |
}) | |
writeStream.write(data + '\n') | |
} catch (error) {} | |
line_no++ | |
}) | |
rl.on('close', line => { | |
writeStream.close() | |
console.log('Total lines: ' + line_no) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment