From f4d00b6af953aafe4cdbe42dd1b5e09e1cb4e21e Mon Sep 17 00:00:00 2001 From: Luke Faraone Date: Tue, 2 Apr 2013 10:59:12 -0700 Subject: [PATCH] [manual] Push new users' data to MailChimp. This creates a new management command, subscribe_new_users, which should be run as a daemon process. When new users are created, an event is passed to RabbitMQ including the following data: * Email * Full name * IP address of the person who confirmed registration * Time of registration confirmation MailChimp strongly encourages the collection of the last two to enable responses to abuse requests, and providing more data lowers the chance that we could get banned from their service if complaints do occur. To use this commit, you need to install the "postmonkey" module from PyPI. (imported from commit 20c628c3fa8bb985aaead85a80ad3b38bf94b9dc) --- humbug/settings.py | 3 +++ .../commands/subscribe_new_users.py | 22 +++++++++++++++++++ zephyr/views.py | 12 ++++++++++ 3 files changed, 37 insertions(+) create mode 100644 zephyr/management/commands/subscribe_new_users.py diff --git a/humbug/settings.py b/humbug/settings.py index 0b3dff6240..53f70da37a 100644 --- a/humbug/settings.py +++ b/humbug/settings.py @@ -426,6 +426,9 @@ OPENID_SSO_SERVER_URL = 'https://www.google.com/accounts/o8/id' OPENID_CREATE_USERS = True OPENID_RENDER_FAILURE = openid_failure_handler +MAILCHIMP_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us4' +HUMBUG_FRIENDS_LIST_ID = '84b2f3da6b' + EVENT_LOG_DIR = 'event_log' # Client-side polling timeout for get_events, in milliseconds. diff --git a/zephyr/management/commands/subscribe_new_users.py b/zephyr/management/commands/subscribe_new_users.py new file mode 100644 index 0000000000..8678594f12 --- /dev/null +++ b/zephyr/management/commands/subscribe_new_users.py @@ -0,0 +1,22 @@ +import simplejson +from postmonkey import PostMonkey +from django.core.management.base import BaseCommand +from django.conf import settings + +from zephyr.lib.queue import SimpleQueueClient + +class Command(BaseCommand): + pm = PostMonkey(settings.MAILCHIMP_API_KEY, timeout=10) + + def subscribe(self, ch, method, properties, data): + self.pm.listSubscribe( + id=settings.HUMBUG_FRIENDS_LIST_ID, + email_address=data['EMAIL'], + merge_vars=data['merge_vars'], + double_optin=False, + send_welcome=False) + + def handle(self, *args, **options): + q = SimpleQueueClient() + q.register_json_consumer("signups", self.subscribe) + q.start_consuming() diff --git a/zephyr/views.py b/zephyr/views.py index 7da86c6325..9df155289b 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -42,6 +42,7 @@ from zephyr.lib.response import json_success, json_error, json_response, json_me from zephyr.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp from zephyr.lib.cache import cache_with_key from zephyr.lib.unminify import SourceMap +from zephyr.lib.queue import queue_json_publish from zephyr import tornado_callbacks from confirmation.models import Confirmation @@ -223,6 +224,17 @@ def accounts_register(request): ) notify_new_user(user_profile) + queue_json_publish( + "signups", + { + 'EMAIL': email, + 'merge_vars': { + 'NAME': full_name, + 'OPTIN_IP': request.META['REMOTE_ADDR'], + 'OPTIN_TIME': datetime.datetime.isoformat(datetime.datetime.now()), + }, + }, + lambda event: None) login(request, authenticate(username=email, password=password)) return HttpResponseRedirect(reverse('zephyr.views.home'))