<commit_before>from __future__ import unicode_literals
import os
import random
import unicodedata

from faker import Factory
from django.core.files import File

from saleor.product.models import (GenericProduct, GenericVariant, ProductImage)
from saleor.product.models import Category
from saleor.userprofile.models import User, Address

fake = Factory.create()
PRODUCT_COLLECTIONS = fake.words(10)


def get_or_create_category(name, **kwargs):
    defaults = {
        'description': fake.text()
    }
    defaults.update(kwargs)
    defaults['slug'] = fake.slug(name)

    return Category.objects.get_or_create(name=name, defaults=defaults)[0]


def create_product(**kwargs):
    if random.choice([True, False]):
        collection = random.choice(PRODUCT_COLLECTIONS)
    else:
        collection = ''

    defaults = {
        'name': fake.company(),
        'price': fake.pyfloat(2, 2, positive=True),
        'sku': fake.random_int(1, 100000),
        'stock': fake.random_int(),
        'collection': collection,
        'weight': fake.random_digit(),
        'description': '\n\n'.join(fake.paragraphs(5))
    }
    defaults.update(kwargs)

    return GenericProduct.objects.create(**defaults)


def create_variant(product, **kwargs):
    defaults = {
        'name': fake.word(),
        'stock': fake.random_int(),
        'sku': fake.random_int(1, 100000),
        'price': fake.pyfloat(2, 2, positive=True),
        'product': product
    }
    defaults.update(kwargs)
    return GenericVariant.objects.create(**defaults)



def create_product_image(product, placeholder_dir):
    img_path = "%s/%s" % (placeholder_dir,<commit_msg>Update script for generating random data<commit_after>from __future__ import unicode_literals
import os
import random
import unicodedata

from faker import Factory
from django.core.files import File

from saleor.product.models import (GenericProduct, GenericVariant, ProductImage)
from saleor.product.models import Category
from saleor.userprofile.models import User, Address

fake = Factory.create()
PRODUCT_COLLECTIONS = fake.words(10)


def get_or_create_category(name, **kwargs):
    defaults = {
        'description': fake.text()
    }
    defaults.update(kwargs)
    defaults['slug'] = fake.slug(name)

    return Category.objects.get_or_create(name=name, defaults=defaults)[0]


def create_product(**kwargs):
    if random.choice([True, False]):
        collection = random.choice(PRODUCT_COLLECTIONS)
    else:
        collection = ''

    defaults = {
        'name': fake.company(),
        'price': fake.pyfloat(2, 2, positive=True),
        'collection': collection,
        'weight': fake.random_digit(),
        'description': '\n\n'.join(fake.paragraphs(5))
    }
    defaults.update(kwargs)
    product = GenericProduct.objects.create(**defaults)
    if not product.base_variant:
        product.variants.create(
            name=product.name,
            sku=fake.random_int(1, 100000),
            price=product.price,
            product=product)
    return product


def create_variant(product, **kwargs):
    defaults = {
        'name': fake.word(),
        'sku': fake.random_int(1, 100000),
        'price': product.price,
        'product': product,
        'weight': product.weight,
    }
    defaults.update(kwargs)
    return GenericVariant.objects.create(**defaults)


def create_product_image(product, placeholder_dir):
    img_path = "%s/%s" % (placeholder_dir,
{'fraction_non_alphanumeric': 0.12369033760186263, 'fraction_numerical': 0.012223515715948778, 'mean_word_length': 3.4348387096774196, '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': '7529311', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1000, 'n_words': 218}