Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 59 lines (47 sloc) 2.17 KB
#!/usr/bin/python2.7
import sys
import time
import os
import yaml
import markdown2
import argparse
from mailsnake import MailSnake
from BeautifulSoup import BeautifulSoup
f = open('config.yaml', 'r')
mconfig = yaml.load(f)
f.close()
parser = argparse.ArgumentParser(description='Sends a markdown file to mailchimp as a new campaign.')
parser.add_argument('-m', metavar='in-file', type=argparse.FileType('r'), help='Takes a markdown file and posts it to mailchimp as a new campaign')
parser.add_argument('-k', help='Supply your mailchimp.com api key here.', default=mconfig['key'])
parser.add_argument('-l', help='Which mailing list to post this to?', default=mconfig['list_id'])
parser.add_argument('-f', help='Set to the from_email address of the campaign', default=mconfig['from_email'])
parser.add_argument('-n', help='Set to the from_name of the campaign', default=mconfig['from_name'])
parser.add_argument('-r', help='Set to the to_name of the campaign', default=mconfig['to_name'])
parser.add_argument('-s', help='Give the campaign a subject line.', default='Created with GitDownChimpy')
parser.add_argument('-p', help='Set to the template_id to use', default=mconfig['template_id'])
parser.add_argument('-e', help='Set to the type of campaign you want,(ie. regular, A/B, plain test, rss', default=mconfig['template_id'])
parser.add_argument('-t', help='Name the campaign', default='Another Great GitDownChimpy Campaign')
try:
results = parser.parse_args()
except IOError, msg:
parser.error(str(msg))
markdown = results.m
moptions = {}
moptions['list_id'] = results.l
moptions['subject'] = results.s
moptions['title'] = results.t
moptions['from_email'] = results.f
moptions['from_name'] = results.n
moptions['to_name'] = results.r
moptions['template_id'] = results.p
mailchimp = MailSnake(results.k)
newsletter = results.m.read()
results.m.close
markdowner = markdown2.Markdown()
mhtml = markdowner.convert(newsletter)
mtext = ''.join(BeautifulSoup(mhtml).findAll(text=True))
mcontent = {}
mcontent['html_MAIN'] = mhtml
mcontent['text'] = mtext
campaignid = mailchimp.campaignCreate(type='regular', options=moptions, content=mcontent)
print 'Campaign sucessfully posted to Mailchimp as:' + campaignid
Something went wrong with that request. Please try again.