Created
April 20, 2014 16:30
-
-
Save hyrsky/f3f359045779d7f24f1e to your computer and use it in GitHub Desktop.
Mailchimp: send predefined campaigns to new subscribers
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
#!/bin/env python2 | |
from datetime import date, timedelta | |
import mailchimp | |
campaigns = ['3c505cef16', 'a4c5c49119', '679a0d19cf', '7db2b71ccd'] | |
# ^^^ List of campaigns here | |
listid = '8cde71be10'; | |
# ^^^ List id here | |
def main(): | |
m = mailchimp.Mailchimp('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXX') # API key here | |
c = mailchimp.Campaigns(m) | |
for (i, cid) in enumerate(campaigns): | |
time = (date.today() - timedelta(days=i)).strftime('%Y-%m-%d') | |
options = {'match':'all','conditions':[{'field':'date','op':'eq','value':time}]} | |
subscribers = c.segment_test(list_id=listid, options=options)['total'] | |
print time + ': %u subscribers' % subscribers | |
if subscribers > 0: | |
c.update(cid=cid, name='segment_opts', value=options) | |
copy = c.replicate(cid=cid) | |
c.send(cid=copy['id']) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment