-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ANPL-1540 add management command to write email addresses for a auth0…
… group to a CSV file (#1201) Created afeter Susan Baron owner of Segmentation Tool requested all user emails
- Loading branch information
1 parent
cb36206
commit 166e5b8
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
controlpanel/cli/management/commands/get_customer_emails_csv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]]) |