<commit_before># -*- coding: utf-8 -*-
""" Print a json file with the users in the database."""

import json
from   collections import OrderedDict

from   django.core.management.base import BaseCommand, CommandError

from   assopy       import models as assopy_models


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (

    )

    def handle(self, *args, **options):
        db_users = assopy_models.User.objects.all()
        users = OrderedDict()
        for user in db_users:
            #try:
            users[user.id] = {'name': user.name().encode('utf-8'),
                              'assopy_id': user.id,
                             }

            if user.user:
                conf_user = {'id': user.user.id,
                             'username': user.user.get_username().encode('utf-8'),
                             'email': user.user.email.encode('utf-8'),
                             'date-joined': str(user.user.date_joined).encode('utf-8'),
                            }
                users[user.id].update(conf_user)
            #except:
            #    import ipdb; ipdb.set_trace()
            #else:
            print(json.dumps(users, indent=2, separators=(',', ': ')))
<commit_msg>fix p3 users command<commit_after># -*- coding: utf-8 -*-
""" Print a json file with the users in the database."""

import json
import logging as log
from   collections import OrderedDict

from   django.core.management.base import BaseCommand, CommandError

from   assopy       import models as assopy_models


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (

    )

    def handle(self, *args, **options):
        db_users = assopy_models.User.objects.all()
        users = OrderedDict()
        for u in db_users:
            try:
                user_name = u.name()
                user_id   = u.user.id
            except:
                log.error('Error with user {}.'.format(u.id))
                users[u.id] = {'assopy_id': u.id,}
            else:
                users[u.id] = {'name': user_name.encode('utf-8'),
                               'assopy_id': u.id,
                               'id': user_id,
                               'username': u.user.get_username().encode('utf-8'),
                               'email': u.user.email.encode('utf-8'),
                               'date-joined': str(u.user.date_joined).encode('utf-8'),
                               }

        print(json.dumps(users, indent=2, separators=(',', ': ')))

{'fraction_non_alphanumeric': 0.1290577988915281, 'fraction_numerical': 0.005146476642913698, 'mean_word_length': 1.570701932858596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6622870', 'n_tokens_mistral': 721, 'n_tokens_neox': 704, 'n_words': 155}