From a086b2b3fbf13aaf6c358f9cdb45e36d55e3acc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Mon, 4 Dec 2023 14:29:00 -0500 Subject: [PATCH] version initiale --- .env.template | 4 ++++ .gitignore | 5 +++++ postmark-unsub-python.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 .env.template create mode 100644 .gitignore create mode 100644 postmark-unsub-python.py diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..afdf043 --- /dev/null +++ b/.env.template @@ -0,0 +1,4 @@ +LISTMONK_USERNAME= +LISTMONK_PASSWORD= +LISTMONK_API_URL= +POSTMARK_SUPPRESSION_JSON= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b35333b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/suppressions-broadcast-2023-12-04T13_00-05_00.json +/suppressions-broadcast-2023-09-22T10_52-04_00.json +/.env +/.ipynb_checkpoints/ +/.idea/ diff --git a/postmark-unsub-python.py b/postmark-unsub-python.py new file mode 100644 index 0000000..dec0e3e --- /dev/null +++ b/postmark-unsub-python.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[ ]: +import os + +import pandas as pd +import requests +import json + +import dotenv + +# In[ ]: +dotenv.load_dotenv() + +# In[ ]: +suppr_data = pd.read_json(os.getenv("POSTMARK_SUPPRESSION_JSON")) + +# In[ ]: +username = os.getenv("LISTMONK_USERNAME") +password = os.getenv("LISTMONK_PASSWORD") +listmonk_api_url = os.getenv("LISTMONK_API_URL") + +# In[ ]: +subscribers = requests.get(f"{listmonk_api_url}/subscribers?page=1&per_page=all", auth=(username, password)) + +# In[ ]: +subsc_data = pd.DataFrame(json.loads(subscribers.content.decode("utf-8"))['data']['results']) + +# In[ ]: +id_a_supprimer = list(suppr_data.merge(subsc_data, how="inner", left_on="email_address", right_on="email")["id"]) + +# In[ ]: +for id in id_a_supprimer: + res = requests.put(f"{listmonk_api_url}/subscribers/{id}/blocklist", auth=(username, password)) + print(res.status_code)