Created
November 22, 2016 10:39
-
-
Save StephanHoyer/0a5feaa7670f4bcfacd224ac7234f09c to your computer and use it in GitHub Desktop.
make a diff-list of two mailchimp exports
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
'use strict'; | |
var fsp = require('fs-promise'); | |
var differenceBy = require('lodash/differenceBy'); | |
var keys = require('lodash/keys'); | |
var values = require('lodash/values'); | |
var parseCsv = require('csv-parse'); | |
function parse(fileContent) { | |
return new Promise(function(resolve, reject) { | |
parseCsv(fileContent, {delimiter: ',', quote: '"', columns: true}, function (err, data) { | |
if (err) { | |
reject(err); | |
} else { | |
resolve(data); | |
} | |
}); | |
}); | |
} | |
Promise.all([ | |
fsp.readFile('listA.csv', 'utf8').then(parse), | |
fsp.readFile('listB.csv', 'utf8').then(parse) | |
]).then(function(res) { | |
var usersNl = res[0]; | |
var users = res[1]; | |
var header = keys(users[0]).join('","'); | |
var rows = differenceBy(users, usersNl, 'Email Address').map(function(user) { | |
return values(user).join('","'); | |
}); | |
var out = '"' + [header].concat(rows).join('"\n"') + '"'; | |
fsp.writeFile('listA-listB.csv', out, 'utf8'); | |
}); |
Do not use MS Excel to modify lists before re-importing to Mailchimp. Script is working beautifully.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
listA.csv
,listB.csv
)node diff.js
listA-listB.csv