admin-scripts/get_emails.py

38 lines
1.0 KiB
Python
Executable File

#!/usr/bin/python3
import os
import api_requests as api
from dotenv import load_dotenv
load_dotenv()
ENDPOINTS = {'mailcow' : 'get/mailbox/all',
'nextcloud' : 'cloud/users',
'gitea' : 'admin/users',
'mattermost' : 'users'}
emails = []
for user in api.gitea(ENDPOINTS["gitea"]):
emails.append(user["email"])
for user in api.mattermost(ENDPOINTS["mattermost"]):
if "is_bot" not in user:
emails.append(user["email"])
try:
for user in api.mailcow(ENDPOINTS["mailcow"]):
if user["username"] not in os.environ["EXCLUDED_EMAILS"]:
emails.append(user["username"])
except TypeError:
print("Mailcow : What is your IP address ?")
for user in api.nextcloud(ENDPOINTS["nextcloud"])["ocs"]["data"]["users"]:
emails.append(api.nextcloud(ENDPOINTS["nextcloud"] + '/' + user)["ocs"]["data"]["email"])
emails = sorted(set(emails))
print("Emails count : " + str(len(emails)))
print("=================")
for email in emails:
print(email + ';')