Created
March 14, 2012 01:18
-
-
Save johnnyhalife/2033179 to your computer and use it in GitHub Desktop.
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
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