version initiale
This commit is contained in:
commit
a086b2b3fb
3 changed files with 45 additions and 0 deletions
4
.env.template
Normal file
4
.env.template
Normal file
|
@ -0,0 +1,4 @@
|
|||
LISTMONK_USERNAME=
|
||||
LISTMONK_PASSWORD=
|
||||
LISTMONK_API_URL=
|
||||
POSTMARK_SUPPRESSION_JSON=
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -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/
|
36
postmark-unsub-python.py
Normal file
36
postmark-unsub-python.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue