Skip to content

Instantly share code, notes, and snippets.

@humitos
Created January 23, 2023 10:08
Show Gist options
  • Save humitos/3e08ed4763a9312f5c0a9a997ea95a42 to your computer and use it in GitHub Desktop.
Save humitos/3e08ed4763a9312f5c0a9a997ea95a42 to your computer and use it in GitHub Desktop.
Script to email owners of organizations that have domains already on Cloudflare.
"""
Script to email owners of organizations
that have domains already on Cloudflare.
We are asking more about their setup.
Email at https://pad.riseup.net.....
"""
from pprint import pprint
import requests
from django.contrib.auth.models import User
from readthedocs.core.utils.contact import contact_users
from readthedocs.projects.models import Domain
pending_domains = [
"example.com"
]
def get_email():
url = 'https://pad.riseup.net/p/..../export/txt'
content = requests.get(url).text.split('\n')
email_subject = content[0].strip()
email_content = '\n'.join(content[1:]).strip()
return email_subject, email_content
def get_users():
return User.objects.filter(
owner_organizations__projects__domains__domain__in=pending_domains,
).distinct()
def get_context(user):
domains = Domain.objects.filter(
project__organizations__owners=user,
domain__in=pending_domains,
).distinct()
return {
'pending_domains': domains,
}
def email_owners(dryrun=True):
email_subject, email_content = get_email()
response = contact_users(
users=get_users(),
email_subject=email_subject,
email_content=email_content,
from_email="Read the Docs <support@readthedocs.com>",
context_function=get_context,
dryrun=dryrun,
)
pprint(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment