<commit_before>from datetime import datetime
import string
from uuid import UUID

from django.core.management import BaseCommand
from django.utils import timezone

from agir.lib.mailtrain import update_person
from agir.people.models import Person

PADDING = "0000000-0000-0000-0000-000000000000"


class Command(BaseCommand):
    help = "Synchronize all the database with mailtrain"

    def handle(self, *args, **kwargs):
        start = datetime.now()
        i = 0

        min_letter = string.hexdigits[timezone.now().day % 8 * 2]
        max_letter = string.hexdigits[(timezone.now().day + 1) % 8 * 2]

        qs = Person.objects.filter(id__gte=UUID(min_letter + PADDING))
        if max_letter > min_letter:
            qs = qs.filter(id__lt=UUID(max_letter + PADDING))

        for person in qs.iterator():
            update_person(person)
            if kwargs["verbosity"] > 1:
                print("Updated %s " % person.email)

            i += 1

        duration = datetime.now() - start

        print(
            f"Updated people from {min_letter} to {max_letter} ({str(i)}) in {str(duration.seconds)} seconds."
        )
<commit_msg>feat: display number of updated people when mailtrain_updated crashes<commit_after>from datetime import datetime
import string
from uuid import UUID

from django.core.management import BaseCommand
from django.utils import timezone

from agir.lib.mailtrain import update_person
from agir.people.models import Person

PADDING = "0000000-0000-0000-0000-000000000000"


class Command(BaseCommand):
    help = "Synchronize all the database with mailtrain"

    def handle(self, *args, **kwargs):
        start = datetime.now()
        i = 0

        min_letter = string.hexdigits[timezone.now().day % 8 * 2]
        max_letter = string.hexdigits[(timezone.now().day + 1) % 8 * 2]

        qs = Person.objects.filter(id__gte=UUID(min_letter + PADDING))
        if max_letter > min_letter:
            qs = qs.filter(id__lt=UUID(max_letter + PADDING))

        try:
            for person in qs.iterator():
                update_person(person)
                if kwargs["verbosity"] > 1:
                    print("Updated %s " % person.email)

                i += 1
        except Exception as e:
            duration = datetime.now() - start
            print(
                f"Updated {i} people over {qs.count()} in {str(duration.seconds)} seconds."
            )

            raise e

        duration = datetime.now() - start

        print(
            f"Updated people from {min_letter} to {max_letter} ({str(i)}) in {str(duration.seconds)} seconds."
        )

{'fraction_non_alphanumeric': 0.10427807486631016, 'fraction_numerical': 0.029793735676088617, 'mean_word_length': 2.4057217165149547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '6810156', 'n_tokens_mistral': 840, 'n_tokens_neox': 752, 'n_words': 207}