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


Python settings.MAILCHIMP_API_KEY属性代码示例

本文整理汇总了Python中django.conf.settings.MAILCHIMP_API_KEY属性的典型用法代码示例。如果您正苦于以下问题:Python settings.MAILCHIMP_API_KEY属性的具体用法?Python settings.MAILCHIMP_API_KEY怎么用?Python settings.MAILCHIMP_API_KEY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.conf.settings的用法示例。


在下文中一共展示了settings.MAILCHIMP_API_KEY属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: consume

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 别名]
def consume(self, data: Dict[str, Any]) -> None:
        # TODO: This is the only implementation with Dict cf Mapping; should we simplify?
        user_profile = get_user_profile_by_id(data['user_id'])
        logging.info(
            "Processing signup for user %s in realm %s",
            user_profile.id, user_profile.realm.string_id,
        )
        if settings.MAILCHIMP_API_KEY and settings.PRODUCTION:
            endpoint = "https://{}.api.mailchimp.com/3.0/lists/{}/members".format(
                settings.MAILCHIMP_API_KEY.split('-')[1], settings.ZULIP_FRIENDS_LIST_ID,
            )
            params = dict(data)
            del params['user_id']
            params['list_id'] = settings.ZULIP_FRIENDS_LIST_ID
            params['status'] = 'subscribed'
            r = requests.post(endpoint, auth=('apikey', settings.MAILCHIMP_API_KEY), json=params, timeout=10)
            if r.status_code == 400 and ujson.loads(r.text)['title'] == 'Member Exists':
                logging.warning("Attempted to sign up already existing email to list: %s",
                                data['email_address'])
            elif r.status_code == 400:
                retry_event(self.queue_name, data, lambda e: r.raise_for_status())
            else:
                r.raise_for_status() 
开发者ID:zulip,项目名称:zulip,代码行数:25,代码来源:queue_processors.py

示例2: handle

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 别名]
def handle(self, *args: Any, **options: Optional[str]) -> None:
        api_key = options['api_key']
        if api_key is None:
            try:
                if settings.MAILCHIMP_API_KEY is None:
                    raise CommandError('MAILCHIMP_API_KEY is None. Check your server settings file.')
                api_key = settings.MAILCHIMP_API_KEY
            except AttributeError:
                raise CommandError('Please supply a MailChimp API key to --api-key, or add a '
                                   'MAILCHIMP_API_KEY to your server settings file.')

        if options['list_id'] is None:
            try:
                if settings.ZULIP_FRIENDS_LIST_ID is None:
                    raise CommandError('ZULIP_FRIENDS_LIST_ID is None. Check your server settings file.')
                options['list_id'] = settings.ZULIP_FRIENDS_LIST_ID
            except AttributeError:
                raise CommandError('Please supply a MailChimp List ID to --list-id, or add a '
                                   'ZULIP_FRIENDS_LIST_ID to your server settings file.')

        endpoint = "https://{}.api.mailchimp.com/3.0/lists/{}/members".format(
            api_key.split('-')[1], options['list_id'],
        )

        for user in UserProfile.objects.filter(is_bot=False, is_active=True) \
                                       .values('email', 'full_name', 'realm_id'):
            data = {
                'email_address': user['email'],
                'list_id': options['list_id'],
                'status': 'subscribed',
                'merge_fields': {
                    'NAME': user['full_name'],
                    'REALM_ID': user['realm_id'],
                    'OPTIN_TIME': options['optin_time'],
                },
            }
            r = requests.post(endpoint, auth=('apikey', api_key), json=data, timeout=10)
            if r.status_code == 400 and ujson.loads(r.text)['title'] == 'Member Exists':
                print("{} is already a part of the list.".format(data['email_address']))
            elif r.status_code >= 400:
                print(r.text) 
开发者ID:zulip,项目名称:zulip,代码行数:43,代码来源:add_users_to_mailing_list.py

示例3: get_mailchimp_api

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 别名]
def get_mailchimp_api():
    if hasattr(settings, 'MAILCHIMP_API_KEY'):
        key = settings.MAILCHIMP_API_KEY
    else:
        key = '00000000000000000000000000000000-us1'
    return mailchimp.Mailchimp(key) 
开发者ID:electionscience,项目名称:approval_frame,代码行数:8,代码来源:mailchimp_api.py

示例4: form_valid

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 别名]
def form_valid(self, form):
        mailchimp_enabled = settings.MAILCHIMP_API_KEY and settings.MAILCHIMP_LIST_ID

        dummy_key = 'a' * 32

        client = MailChimp(mc_api=settings.MAILCHIMP_API_KEY or dummy_key, timeout=5.0, enabled=mailchimp_enabled)

        data = form.cleaned_data.copy()
        email = data.pop('email')
        data = {
            k.upper(): v
            for k, v in data.items()
        }
        try:
            client.lists.members.create(settings.MAILCHIMP_LIST_ID, {
                'email_address': email,
                'status': 'pending',
                'merge_fields': data,
            })
        except Exception as e:
            self.warning(e)
        else:
            if mailchimp_enabled:
                self.success()
            else:
                self.warning(Exception(
                    'Incorrect Mailchimp configuration: API_KEY: {}, LIST_ID: {}'.format(
                        str(settings.MAILCHIMP_API_KEY),
                        str(settings.MAILCHIMP_LIST_ID),
                    )
                ))

        return super().form_valid(form) 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:35,代码来源:views.py

示例5: global_vars

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 别名]
def global_vars(request):
    return {
        'APPLY_SITE': ApplyHomePage.objects.first().get_site(),
        'PUBLIC_SITE': HomePage.objects.first().get_site(),
        'newsletter_form': NewsletterForm(),
        'newsletter_enabled': settings.MAILCHIMP_API_KEY and settings.MAILCHIMP_LIST_ID,
        'ORG_LONG_NAME': settings.ORG_LONG_NAME,
        'ORG_SHORT_NAME': settings.ORG_SHORT_NAME,
        'ORG_EMAIL': settings.ORG_EMAIL,
    } 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:12,代码来源:context_processors.py

示例6: _get_base_url

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 别名]
def _get_base_url(self):
        dc = settings.MAILCHIMP_API_KEY.split('-')[-1]

        return f'https://{dc}.api.mailchimp.com/3.0/' 
开发者ID:f213,项目名称:education-backend,代码行数:6,代码来源:mailchimp.py

示例7: _post

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 别名]
def _post(self, url: str, payload: dict):
        response = requests.post(
            url=self.format_url(url),
            auth=HTTPBasicAuth('user', settings.MAILCHIMP_API_KEY),
            json=payload,
        )
        if response.status_code != 200:
            raise AppMailchimpWrongResponseException(f'Wrong response from mailchimp: {response.status_code}. Response = {response.json()}')

        return response 
开发者ID:f213,项目名称:education-backend,代码行数:12,代码来源:mailchimp.py

示例8: member_pre_save_cb

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 别名]
def member_pre_save_cb(sender, instance, raw, **kwargs):
    """
    Subscribe or unsubscribe a user from Mailchimp.
    """
    if raw or settings.TESTING:
        return

    try:
        member = sender.objects.get(pk=instance.pk)
    except sender.DoesNotExist:
        pass
    else:
        if member.newsletter == instance.newsletter:
            return

    if not settings.MAILCHIMP_API_KEY:
        logger.warn(
            "User changed email preference but no Mailchimp API key "
            "has been specified, set MAILCHIMP_API_KEY."
        )

        return

    mc = mailchimp.Mailchimp(settings.MAILCHIMP_API_KEY)

    try:
        address = instance.primary_email.email
    except AttributeError:
        # We're not sure why the callback is firing an extra time, before
        # SignupView.create_account runs (when email not yet saved).
        return

    if instance.newsletter:
        try:
            mc.lists.subscribe(
                settings.MAILCHIMP_NEWSLETTER_LIST,
                {"email": address},
                double_optin=False,
                update_existing=True,
            )
        except mailchimp.ListAlreadySubscribedError:
            logger.info('"%s" was already subscribed', address)
        except (mailchimp.Error, ValueError) as e:
            logger.error("A Mailchimp error occurred: %s, %s", e.__class__, e)
    else:
        try:
            mc.lists.unsubscribe(
                settings.MAILCHIMP_NEWSLETTER_LIST,
                {"email": address},
                send_goodbye=False,
                send_notify=False,
            )
        except (mailchimp.ListNotSubscribedError, mailchimp.EmailNotExistsError):
            logger.info('"%s" was already unsubscribed', address)
        except (mailchimp.Error, ValueError) as e:
            logger.error("A Mailchimp error occurred: %s, %s", e.__class__, e) 
开发者ID:OpenHumans,项目名称:open-humans,代码行数:58,代码来源:signals.py


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