Skip to content

Instantly share code, notes, and snippets.

@johnnyhalife
Created March 14, 2012 01:18
Show Gist options
  • Save johnnyhalife/2033179 to your computer and use it in GitHub Desktop.
Save johnnyhalife/2033179 to your computer and use it in GitHub Desktop.
var MailChimpAPI = require('mailchimp').MailChimpAPI;
var crypto = require('crypto')
, mongoose = require('mongoose')
, _ = require('underscore');
var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
var InvitationType = new Schema({
key : ObjectId,
hash : String,
email : String,
timestamp : { type: Date, default: Date.now }
});
var Invitation = mongoose.model('Invitation', InvitationType);
mongoose.connect(process.env.MONGOLAB_URI);
Invitation.remove(function(err, affected){
console.log("[APP] Cleaned up " + affected + " records");
});
var api = new MailChimpAPI(apiKey, { version : '1.3', secure : true });
api.listMembers({id: MAILCHIMP_LIST_ID, limit: 15000}, function(res){
var index = 1;
_.forEach(res.data, function(entry){
api.listMemberInfo({id: MAILCHIMP_LIST_ID, email_address: entry.email}, function(users) {
if(!users.data) return;
var user = users.data[0].merges;
if(!user) return;
console.log("[APP] processed " + index + "/" + res.data.length + " with " + user['INVITE'] + " " + user['EMAIL']);
var invite = new Invitation({hash: user['INVITE'], email: user['EMAIL']});
invite.save(function(err){});
index++;
});
});
});
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment