<commit_before>from optparse import make_option

from django.core.management.base import BaseCommand
from django.db import connection

from celery.messaging import establish_connection


class Command(BaseCommand):

    help = """A one time command to convert user fields.  See
    http://blog.mozilla.com/addons/2010/07/26/upcoming-changes-to-amo-accounts/
    for details."""

    option_list = BaseCommand.option_list + (
        make_option('--date', '-d', dest='date',
                    help='Only process accounts after this date.'),
        )

    def handle(self, *args, **options):
        from users.tasks import add_usernames
        from amo.utils import chunked

        date = options.get('date', False)

        print "Getting users..."
        cursor = connection.cursor()

        if date:
        # Doing this directly because I don't want to load 800k user objects
            query = """SELECT id, firstname, lastname, nickname
                       FROM users
                       WHERE modified > %s
                       OR created > %s"""
            cursor.execute(query, [date, date])
        else:
            cursor.execute("SELECT id, firstname, lastname, nickname FROM users")

<commit_msg>Only grab users with null usernames<commit_after>from optparse import make_option

from django.core.management.base import BaseCommand
from django.db import connection

from celery.messaging import establish_connection


class Command(BaseCommand):

    help = """A one time command to convert user fields.  See
    http://blog.mozilla.com/addons/2010/07/26/upcoming-changes-to-amo-accounts/
    for details."""

    option_list = BaseCommand.option_list + (
        make_option('--date', '-d', dest='date',
                    help='Only process accounts after this date.'),
        )

    def handle(self, *args, **options):
        from users.tasks import add_usernames
        from amo.utils import chunked

        date = options.get('date', False)

        print "Getting users..."
        cursor = connection.cursor()

        if date:
        # Doing this directly because I don't want to load 800k user objects
            query = """SELECT id, firstname, lastname, nickname
                       FROM users
                       WHERE
                       username IS NULL AND
                       (modified > %s
                       OR created > %s)"""
            cursor.execute(query, [date, date])
        else:
            cursor.execute("""SELECT id, firstname, lastname, nickname FROM users
                              WHERE username IS NULL""")


{'fraction_non_alphanumeric': 0.09384615384615384, 'fraction_numerical': 0.008461538461538461, 'mean_word_length': 2.0314685314685317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3222095', 'n_tokens_mistral': 696, 'n_tokens_neox': 639, 'n_words': 215}