def handle(self, *args, **options): # Product.objects.all().delete() cats = [ Category.objects.create( title="{} {}".format(silly.adjective(), silly.noun().title()), description=silly.paragraph(length=2) + "\n" + silly.paragraph(length=2), image_url=silly.image(), ) for i in range(8) ] for i in range(100): title = "{} {}".format(silly.adjective(), silly.noun()) desc = silly.paragraph(length=2) + "\n" + silly.paragraph(length=2) price = silly.number() + silly.number() / 10 Product.objects.create( category=random.choice(cats), title=title, description=desc, price=price, image_url=silly.image(), ) print("OK")
def handle(self, *args, **options): n = 100 for i in tqdm.tqdm(range(n)): try: user_name = self.get_silly_username() email = silly.email() password = self.get_silly_username() gender = Gender.MALE if randint(1, 3) == 3 else Gender.FEMALE status = Status.DIVORCEE if randint(1, 4) == 4 else Status.SINGLE dob = silly.datetime().date() is_cohen = True if randint(1, 6) == 6 else False picture = "text" while "placekitten" not in picture: picture = silly.image(width=i+140*2, height=i+95*2).replace(" ", "%20") is_single = True # is_single = True if round(i % 3, 1) == randint(0, 1) else False user = User.objects.create_user("{}".format(user_name), email, password) # Add new user to Profile p = models.Profile( user=user, gender=gender, status=status, dob=dob, is_cohen=is_cohen, is_single=is_single, picture=picture, ) p.full_clean() p.save() except IntegrityError: print("UNIQUE constraint failed: auth_user.username") print("OK")
def handle(self, *args, **options): # Product.objects.all().delete() cats = [ Category.objects.create( title="{} {}".format(silly.adjective(), silly.noun().title()), description=silly.paragraph(length=2) + "\n" + silly.paragraph( length=2), image_url=silly.image(), ) for i in range(8)] for i in range(100): title = "{} {}".format(silly.adjective(), silly.noun()) desc = silly.paragraph(length=2) + "\n" + silly.paragraph(length=2) price = silly.number() + silly.number() / 10 Product.objects.create( category=random.choice(cats), title=title, description=desc, price=price, image_url=silly.image(), ) print("OK")
def handle(self, *args, **options): n = 100 for i in tqdm.tqdm(range(n)): try: user_name = self.get_silly_username() email = silly.email() password = self.get_silly_username() gender = Gender.MALE if randint(1, 3) == 3 else Gender.FEMALE status = Status.DIVORCEE if randint(1, 4) == 4 else Status.SINGLE dob = silly.datetime().date() is_cohen = True if randint(1, 6) == 6 else False picture = "text" while "placekitten" not in picture: picture = silly.image(width=i + 140 * 2, height=i + 95 * 2).replace( " ", "%20") is_single = True # is_single = True if round(i % 3, 1) == randint(0, 1) else False user = User.objects.create_user("{}".format(user_name), email, password) # Add new user to Profile p = models.Profile( user=user, gender=gender, status=status, dob=dob, is_cohen=is_cohen, is_single=is_single, picture=picture, ) p.full_clean() p.save() except IntegrityError: print("UNIQUE constraint failed: auth_user.username") print("OK")
def handle(self, *args, **options): # Product.objects.all().delete() for i in range(5): parent_title = "{} {}".format(silly.adjective(), silly.noun()) parent_desc = silly.paragraph(length=2) + "\n" + silly.paragraph( length=2) parent = Category.objects.create( title=parent_title, description=parent_desc, ) for j in range(5): title = "{} {}".format(silly.adjective(), silly.noun()) desc = silly.paragraph(length=2) + "\n" + silly.paragraph( length=2) price = silly.number() + silly.number() / 10 image_url = silly.image() Category.objects.create(title=title, description=desc, price=price, image_url=image_url, parent=parent)
import silly import requests import mimetypes image = silly.image() print(image) response = requests.head(image) content_type = response.headers['content-type'] extension = mimetypes.guess_extension(content_type) print(extension) open('image.png', 'wb').write(requests.get(image).content) print(silly.sentence())