当前位置: 首页>>代码示例>>Python>>正文


Python PostMonkey.listMembers方法代码示例

本文整理汇总了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'))
开发者ID:funkatron,项目名称:ncs-notifications,代码行数:54,代码来源:__init__.py

示例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'))
开发者ID:gizmomathboy,项目名称:ncs-notifications,代码行数:49,代码来源:__init__.py


注:本文中的postmonkey.PostMonkey.listMembers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。