diff --git a/settings.py b/settings.py index 4d9f344..1c76e67 100755 --- a/settings.py +++ b/settings.py @@ -110,6 +110,7 @@ INSTALLED_APPS = ( 'sso', 'groups', 'api', + 'tools', ) ## Server Mail diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/management/__init__.py b/tools/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/management/commands/extract-emails.py b/tools/management/commands/extract-emails.py new file mode 100755 index 0000000..ae43d9e --- /dev/null +++ b/tools/management/commands/extract-emails.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import unicodedata +import re +from optparse import make_option +from django.core.management.base import BaseCommand, CommandError +from eve_api.models import EVEPlayerCharacter +from eve_api.app_defines import API_STATUS_OK + +class Command(BaseCommand): + help = ("Extracts a list of emails for a corp domain") + + option_list = BaseCommand.option_list + ( + make_option('-a', '--alli', action='store', dest='alliance', help='Alliance ID of the extract'), + make_option('-c', '--corp', action='store', dest='corporation', help='Corp ID of the extract'), + make_option('-d', '--domain', action='store', dest='domain', help='Domain of the extract') + ) + + requires_model_validation = False + + def handle(self, **options): + + if not options.get('alliance', None) and not options.get('corporation', None): + raise CommandError("Please provide either a corporation or alliance") + + if options.get('alliance', None) and options.get('corporation', None): + raise CommandError("Use either alliance or corporation, not both") + + if not options.get('domain', None): + raise CommandError("You need to specify a domain") + + alliance = options.get('alliance', None) + corporation = options.get('corporation', None) + domain = options.get('domain', None) + + chars = EVEPlayerCharacter.objects.select_related('eveaccount__user').filter(eveaccount__api_status=API_STATUS_OK, eveaccount__isnull=False) + if alliance: + chars = chars.filter(corporation__alliance__id=alliance) + elif corporation: + chars = chars.filter(corporation__id=corporation) + + for char in chars: + charname = re.sub('[^a-zA-Z0-9_-]+', '', unicodedata.normalize('NFKD', char.name).encode('ASCII', 'ignore')) + if charname and char.eveaccount_set.all()[0].user.email: + print "%s@%s\t%s" % (charname.lower(), domain, char.eveaccount_set.all()[0].user.email) diff --git a/tools/models.py b/tools/models.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/views.py b/tools/views.py new file mode 100644 index 0000000..e69de29