Created
August 10, 2019 18:25
-
-
Save astagi/93cbb32f43bcb9ac019a3640ecc6ab9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from createsend import Subscriber | |
from createsend.createsend import BadRequest | |
class CampaignMonitorException(Exception): | |
pass | |
class CampaignMonitorListSubscriber(): | |
def __init__(self, api_key, list_id): | |
self._api_key = api_key | |
self._list_id = list_id | |
def subscribe(self, email, name, custom_fields, resubscribe, consent_to_track): | |
try: | |
subscriber = Subscriber( | |
{'api_key': self._api_key}, | |
self._list_id | |
) | |
subscriber.add(list_id, email, name, custom_fields, resubscribe, consent_to_track) | |
except BadRequest as ex: | |
raise CampaignMonitorException(str(ex)) | |
def unsubscribe(self, email): | |
try: | |
subscriber = Subscriber( | |
{'api_key': self._api_key}, | |
self._list_id, | |
email, | |
) | |
subscriber.unsubscribe() | |
except BadRequest as ex: | |
raise CampaignMonitorException(str(ex)) | |
def delete(self, email): | |
try: | |
subscriber = Subscriber( | |
{'api_key': self._api_key}, | |
self._list_id, | |
email, | |
) | |
subscriber.delete() | |
except BadRequest as ex: | |
raise CampaignMonitorException(str(ex)) | |
if __name__ == '__main__': | |
api_key = 'APIK3YAPIK3YAPIK3YAPIK3Y' | |
list_id = 'L1ST1DL1ST1DL1ST1DL1ST1D' | |
cmls = CampaignMonitorListSubscriber(api_key, list_id) | |
try: | |
cmls.subscribe("[email protected]", "Andrea Stagi", None, True, 'yes') | |
cmls.unsubscribe("[email protected]") | |
cmls.delete("[email protected]") | |
except CampaignMonitorException as ex: | |
print (ex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment