Skip to content

Commit 6111bca

Browse files
committed
Merge branch 'master' into ghost_api_update
2 parents ecb923a + 11e5b5d commit 6111bca

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

common/helpers/mailing_list.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import threading
2-
from mailchimp import Mailchimp, ListDoesNotExistError, EmailNotExistsError, ListAlreadySubscribedError, Error
2+
from mailchimp3 import MailChimp
33
from django.conf import settings
44

55

@@ -13,23 +13,33 @@ def __init__(self, email, first_name, last_name):
1313
thread.start()
1414

1515
def print_error(self, err_msg):
16-
err_msg = 'Failed to subscribe {first} {last}({email}) to mailing list: {err_msg}'.format(
17-
first=self.first_name, last=self.last_name, email=self.email, err_msg=err_msg)
16+
err_msg = "Failed to subscribe {first} {last}({email}) to mailing list: {err_msg}".format(
17+
first=self.first_name,
18+
last=self.last_name,
19+
email=self.email,
20+
err_msg=err_msg,
21+
)
1822
print(err_msg)
1923

2024
def run(self):
2125
if settings.MAILCHIMP_API_KEY is None:
22-
self.print_error('MAILCHIMP_API_KEY not set')
26+
self.print_error("MAILCHIMP_API_KEY not set")
2327
return False
2428

2529
api_key = settings.MAILCHIMP_API_KEY
2630
list_id = settings.MAILCHIMP_SUBSCRIBE_LIST_ID
2731

28-
api = Mailchimp(api_key)
32+
api = MailChimp(api_key)
2933
try:
30-
merge_vars = {'FNAME': self.first_name, 'LNAME': self.last_name}
31-
api.lists.subscribe(list_id, {'email': self.email}, merge_vars=merge_vars)
32-
except (ListDoesNotExistError, EmailNotExistsError, ListAlreadySubscribedError, Error) as e:
34+
merge_fields = {"FNAME": self.first_name, "LNAME": self.last_name}
35+
api.lists.members.create(
36+
list_id,
37+
{
38+
"email_address": self.email,
39+
"status": "subscribed",
40+
"merge_fields": merge_fields,
41+
},
42+
)
43+
except (Exception) as e:
3344
self.print_error(repr(e))
3445
return False
35-

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ djangorestframework==3.14.0
1919
docutils==0.14
2020
gunicorn==19.6.0
2121
jmespath==0.9.3
22-
mailchimp==2.0.9
22+
mailchimp3==3.0.21
2323
psycopg2==2.9.6
2424
psycopg2-binary==2.9.6
2525
python-dateutil==2.8.2

0 commit comments

Comments
 (0)