Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - mailchimp experiments #5808

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
22 changes: 22 additions & 0 deletions website/classes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import uuid

from flask import make_response, redirect, request, session
Expand Down Expand Up @@ -49,6 +50,27 @@ def create_class(self, user):
"name": body["name"],
}

# from auth, where we also use this for mailinglist subscriptions

import os

from .auth import MAILCHIMP_API_URL, MAILCHIMP_API_HEADERS

import requests
import hashlib

subscriber = user["email"].encode('utf-8')
subscriber_hash = hashlib.md5(subscriber).hexdigest()

# mailchimp docs: https://mailchimp.com/developer/marketing/api/list-member-tags/add-or-remove-member-tags/

request_body = {"tags": [{"name": "class_created", "status": "active"}]}
try:
r = requests.post(MAILCHIMP_API_URL + f"/members/{subscriber_hash}/tags",
headers=MAILCHIMP_API_HEADERS, data=json.dumps(request_body))
except Exception as E:
pass

self.db.store_class(Class)
response = {"id": Class["id"]}
return make_response(response, 200)
Expand Down
Loading