Skip to content

Instantly share code, notes, and snippets.

@rjyo
Created October 28, 2012 14:53
Show Gist options
  • Save rjyo/3968803 to your computer and use it in GitHub Desktop.
Save rjyo/3968803 to your computer and use it in GitHub Desktop.
get unique emails
var _ = require('underscore')
, redis = require('redis')
, fs = require('fs')
, client = redis.createClient();
var content = fs.readFileSync('./bounces', 'utf-8');
content = JSON.parse(content);
_.each(content.items, function(item) {
client.sadd('mail.del', item.address);
});
content = fs.readFileSync('./complaints', 'utf-8');
content = JSON.parse(content);
_.each(content.items, function(item) {
client.sadd('mail.del', item.address);
});
for (var i = 1; i < 5; i++) {
content = fs.readFileSync('./lohasnews' + i, 'utf-8');
content = JSON.parse(content);
_.each(content.items, function(item) {
if (item.subscribed) client.sadd('mail.all', item.address);
else client.sadd('mail.del', item.address);
});
}
for (var i = 1; i < 5; i++) {
content = fs.readFileSync('./shopnews' + i, 'utf-8');
content = JSON.parse(content);
_.each(content.items, function(item) {
if (item.subscribed) client.sadd('mail.all', item.address);
else client.sadd('mail.del', item.address);
});
}
client.sdiffstore('mail.left', 'mail.all', 'mail.del', redis.print);
client.smembers('mail.left', function(err, results) {
_.each(results, function(r) {
console.log(r);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment