list management

This commit is contained in:
j 2023-10-01 09:07:48 +02:00
parent 55202ba3b0
commit 502f6fb2b9

View file

@ -81,7 +81,7 @@ def add_email(email):
def delete_bounced_emails(): def delete_bounced_emails():
url = settings.LISTMONK_API + 'bounces' url = settings.LISTMONK_API + 'bounces'
auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD) auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD)
r = requests.get(url + '?per_page=10000', auth=auth) r = requests.get(url + '?per_page=10000', auth=auth).json()
ids = [sub['subscriber_id'] for sub in r['data']['results']] ids = [sub['subscriber_id'] for sub in r['data']['results']]
url = settings.LISTMONK_API + 'subscribers' url = settings.LISTMONK_API + 'subscribers'
for id in ids: for id in ids:
@ -90,3 +90,14 @@ def delete_bounced_emails():
print(id) print(id)
def delete_blacklisted_emails():
url = settings.LISTMONK_API + 'subscribers'
auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD)
r = requests.get(url + '?per_page=10000', auth=auth).json()
ids = [u['id'] for u in r['data']['results'] if u['status'] == 'blocklisted']
for id in ids:
r = requests.delete(url + '?id=%s' % id, auth=auth).json()
if not r.get("data"):
print(id)