37 lines
882 B
Python
37 lines
882 B
Python
|
#!/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)
|