<commit_before><commit_msg>add mgmt cmd to generate images and add them to their respective fields<commit_after>from django.core.management.base import BaseCommand, CommandError

from sources.helpers import generate_image_from_text
from sources.models import Person


def generate_images():
    sources = Person.objects.all()

    for source in sources:
        source_id = source.id

        # email address
        # try:
        image_location = generate_image_from_text(
            source_id,
            source.email_address,
            'email_address'
        )
        source.email_address_image = image_location
        source.save()
        # except:
        #     print(f'Failed: email_address - {source_id}')

        # phone number primary
        # try:
        image_location = generate_image_from_text(
            source_id,
            source.phone_number_primary,
            'phone_number_primary'
        )
        source.phone_number_primary_image = image_location
        source.save()
        # except:
            # print(f'Failed: phone_number_primary - {source_id}')

        # phone number secondary
        # try:
        if source.phone_number_secondary:
            image_location = generate_image_from_text(
                source.id,
                source.phone_number_secondary,
                'phone_number_secondary'
            )
            source.phone_number_secondary_image = image_location
            source.save()
        else:
            print(f'N/A: phone_number_secondary - {source_id}')
        # except:
        #     print(f'Failed: phone_number_secondary - {source_id}')


class Command(BaseCommand):
    help = 'Import sources from a csv file.'

    def handle(self, *args, **options):
        generate_images()
{'fraction_non_alphanumeric': 0.07583474816072439, 'fraction_numerical': 0.0, 'mean_word_length': 2.129203539823009, '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': '932167', 'n_tokens_mistral': 477, 'n_tokens_neox': 466, 'n_words': 102}