Skip to content

Commit

Permalink
ANPL-1540 add management command to write email addresses for a auth0…
Browse files Browse the repository at this point in the history
… group to a CSV file (#1201)

Created afeter Susan Baron owner of Segmentation Tool requested all user emails
  • Loading branch information
michaeljcollinsuk authored Sep 11, 2023
1 parent cb36206 commit 166e5b8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions controlpanel/cli/management/commands/get_customer_emails_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Standard library
import csv
from datetime import datetime

# Third-party
from django.core.management import BaseCommand

# First-party/Local
from controlpanel.api import auth0


class Command(BaseCommand):
help = "Writes a CSV with all customer emails for an auth0 group"

def add_arguments(self, parser):
parser.add_argument(
"group_name",
type=str,
help="input: The auth0 group name to get customers emails for"
)

def handle(self, *args, **options):
group_name = options["group_name"]
auth_instance = auth0.ExtendedAuth0()
group_id = auth_instance.groups.get_group_id(group_name)
timestamp = datetime.now().strftime("%d-%m-%Y_%H%M")
with open(f"{group_name}_customers_{timestamp}.csv", "w") as f:
writer = csv.writer(f)
writer.writerow(["Email"])
for customer in auth_instance.groups.get_group_members(group_id):
writer.writerow([customer["email"]])

0 comments on commit 166e5b8

Please sign in to comment.