示例#1
0
    def handle(self, *args, **options):
        """Create fake users and statuses for Mowdie."""
        from faker import Faker
        import random
        from django.conf import settings
        from PyMarkovTextGenerator import Markov

        fake = Faker()
        textgen = Markov(prob=True, level=3)
        with open(settings.BASE_DIR + "/../john_carter.txt") as file:
            textgen.parse(file.read())

        def update_text():
            return textgen.generate(
                startf=lambda db: random.choice([x for x in db
                                                 if x[0][0].isupper()]),
                endf=lambda s: len(s) > 120)

        Favorite.objects.all().delete()
        Update.objects.all().delete()
        User.objects.all().delete()

        users = []
        for _ in range(20):
            user = User(username=fake.user_name(),
                        email=fake.email())
            user.set_password("password")
            user.save()
            Profile(user=user).save()
            users.append(user)

        user = User(username="******",
                    email="*****@*****.**",
                    is_staff=True,
                    is_superuser=True)
        user.set_password("password")
        user.save()
        Profile(user=user).save()

        updates = []
        for _ in range(100):
            update = Update(text=update_text(),
                            posted_at=make_aware(fake.date_time_this_year()),
                            user=random.choice(users))
            update.save()
            updates.append(update)

        combos = random.sample([(user, update)
                                for user in users
                                for update in updates], 200)
        for user, update in combos:
            favorite = Favorite(user=user, update=update)
            favorite.save()
示例#2
0
    def handle(self, *args, **options):
        """Create fake users and statuses for Mowdie."""
        from faker import Faker
        import random
        from django.conf import settings
        from PyMarkovTextGenerator import Markov

        fake = Faker()
        textgen = Markov(prob=True, level=3)
        with open(settings.BASE_DIR + "/../john_carter.txt") as file:
            textgen.parse(file.read())

        def update_text():
            return textgen.generate(
                startf=lambda db: random.choice([x for x in db if x[0][0].isupper()]), endf=lambda s: len(s) > 120
            )

        Favorite.objects.all().delete()
        Update.objects.all().delete()
        User.objects.all().delete()

        users = []
        for _ in range(20):
            user = User(username=fake.user_name(), email=fake.email())
            user.set_password("password")
            user.save()
            Profile(user=user).save()
            users.append(user)

        user = User(username="******", email="*****@*****.**", is_staff=True, is_superuser=True)
        user.set_password("password")
        user.save()
        Profile(user=user).save()

        updates = []
        for _ in range(100):
            update = Update(
                text=update_text(), posted_at=make_aware(fake.date_time_this_year()), user=random.choice(users)
            )
            update.save()
            updates.append(update)

        combos = random.sample([(user, update) for user in users for update in updates], 200)
        for user, update in combos:
            favorite = Favorite(user=user, update=update)
            favorite.save()
    def handle(self, *args, **options):
        '''Create some fake users and statuses'''
        fake = Faker()

        Favorite.objects.all().delete()
        Status.objects.all().delete()
        Profile.objects.all().delete()
        User.objects.all().delete()

        User.objects.create_superuser(username='******',
                                      password='******',
                                      email='')

        users = []
        statuses = []

        for _ in range(50):
            new_user = User(username=fake.user_name(), email=fake.email())
            new_user.set_password('password')
            new_user.save()
            profile = Profile(user=new_user, favorite_color='blue')
            profile.save()
            users.append(new_user)

        for _ in range(1000):
            new_status = Status(user=random.choice(users),
                                posted_at=make_aware(
                                    fake.date_time_this_year()),
                                text=fake.text(max_nb_chars=141))
            new_status.save()
            statuses.append(new_status)

        for _ in range(4000):
            try:
                favorite = Favorite(user=random.choice(users),
                                    status=random.choice(statuses))
                favorite.save()
            except IntegrityError:
                continue
    def handle(self, *args, **options):
        '''Create some fake users and statuses'''
        fake = Faker()

        Favorite.objects.all().delete()
        Status.objects.all().delete()
        Profile.objects.all().delete()
        User.objects.all().delete()

        User.objects.create_superuser(username='******', password='******', email='')

        users = []
        statuses = []

        for _ in range(50):
            new_user = User(username=fake.user_name(),
                            email=fake.email())
            new_user.set_password('password')
            new_user.save()
            profile = Profile(user=new_user, favorite_color='blue')
            profile.save()
            users.append(new_user)

        for _ in range(1000):
            new_status = Status(user=random.choice(users),
                                posted_at=make_aware(fake.date_time_this_year()),
                                text=fake.text(max_nb_chars=141))
            new_status.save()
            statuses.append(new_status)

        for _ in range(4000):
            try:
                favorite = Favorite(user=random.choice(users),
                                    status=random.choice(statuses))
                favorite.save()
            except IntegrityError:
                continue