Skip to content

Instantly share code, notes, and snippets.

@ra4king
Created May 17, 2017 08:52
Show Gist options
  • Save ra4king/f242079e938ecbc6ec9aec9ce6216254 to your computer and use it in GitHub Desktop.
Save ra4king/f242079e938ecbc6ec9aec9ce6216254 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var filename = process.argv[2];
console.log('Fixing ' + filename);
var lines = fs.readFileSync(filename).toString().split('\n');
var output = [];
lines.forEach((s, idx) => {
var regex = /^\[(.+?)\](.+)$/;
var match = regex.exec(s);
if(match) {
var date = new Date(match[1].endsWith('GMT') ? match[1] : match[1] + ' GMT');
output.push({date: date, text: match[2]});
}
});
if(output.length > 0) {
var last_date = output[0].date;
output = output.filter((line, idx) => {
if(line.date >= last_date && (idx == 0 || line.text != output[idx - 1].text)) {
last_date = line.date;
return true;
}
return false;
}).map(line => '[' + line.date.toUTCString() + ']' + line.text);
}
fs.writeFile(filename, output.join('\n') + '\n');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment