本文整理汇总了Python中postmonkey.PostMonkey.listMembers方法的典型用法代码示例。如果您正苦于以下问题:Python PostMonkey.listMembers方法的具体用法?Python PostMonkey.listMembers怎么用?Python PostMonkey.listMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类postmonkey.PostMonkey
的用法示例。
在下文中一共展示了PostMonkey.listMembers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import listMembers [as 别名]
def send():
"""
sends emails to a configured MailChimp list
"""
# get form data (WE SHOULD VALIDATE)
msg_text = request.form.get('message')
subject = request.form.get('subject')
from_email = request.form.get('from_email')
from_name = request.form.get('from_name')
test_list = request.form.get('test_list', None)
if (test_list):
list_id = app.config['PM_TEST_LIST_ID']
app.logger.debug("sending to test list %s" % (list_id))
else:
list_id = app.config['PM_LIST_ID']
app.logger.debug("sending to LIVE list %s" % (list_id))
pm = PostMonkey(app.config['PM_API_KEY'])
md = Mandrill(app.config['MD_API_KEY'])
members = pm.listMembers(id=list_id, limit=1000)
emails = []
for mem in members['data']:
emails.append(mem['email'])
eastern = pytz.timezone('US/Eastern')
now = eastern.localize(datetime.datetime.now())
msg_text = "%s\n\n--------\n\nE-mail generated at %s" % (msg_text, now)
for email in emails:
message = {
"text": msg_text,
"subject": subject,
"from_email": from_email,
"from_name": from_name,
"to": [{
"email": email
}]
}
app.logger.debug("sending to %s at %s" % (email, now))
resp = md.messages.send(message, async=True)
app.logger.debug(pformat(resp))
flash("%s e-mails sent!" % len(emails))
return redirect(url_for('home'))
示例2: send
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import listMembers [as 别名]
def send():
"""
sends emails to a configured MailChimp list
"""
# get form data (WE SHOULD VALIDATE)
msg_text = request.form.get('message')
subject = request.form.get('subject')
from_email = request.form.get('from_email')
from_name = request.form.get('from_name')
pm = PostMonkey(app.config['PM_API_KEY'])
md = Mandrill(app.config['MD_API_KEY'])
members = pm.listMembers(id=app.config['PM_LIST_ID'], limit=1000)
emails = []
for mem in members['data']:
emails.append(mem['email'])
now_utc = datetime.datetime.now() # get naive utc time
local_tz = pytz.timezone('US/Eastern') # set local timezone
now_utc = pytz.utc.localize(now_utc) # add timezone data to utc time
local_time = now_utc.astimezone(local_tz) # convert to local time
msg_text = "%s\n\n--------\n\nE-mail generated at %s" % (msg_text, local_time)
for email in emails:
message = {
"text": msg_text,
"subject": subject,
"from_email": from_email,
"from_name": from_name,
"to": [{
"email": email
}]
}
app.logger.debug("sending to %s" % (email))
resp = md.messages.send(message, async=True)
app.logger.debug(pformat(resp))
flash("%s e-mails sent!" % len(emails))
return redirect(url_for('home'))