You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1012 B

  1. from random import randint
  2. from sqlalchemy.exc import IntegrityError
  3. from faker import Faker
  4. from . import db
  5. from .models import User, Post
  6. def users(count=100):
  7. fake = Faker()
  8. i = 0
  9. while i < count:
  10. u = User(email=fake.email(),
  11. username=fake.user_name(),
  12. password='password',
  13. confirmed=True,
  14. name=fake.name(),
  15. location=fake.city(),
  16. about_me=fake.text(),
  17. member_since=fake.past_date())
  18. db.session.add(u)
  19. try:
  20. db.session.commit()
  21. i += 1
  22. except IntegrityError:
  23. db.session.rollback()
  24. def posts(count=100):
  25. fake = Faker()
  26. user_count = User.query.count()
  27. for i in range(count):
  28. u = User.query.offset(randint(0, user_count - 1)).first()
  29. p = Post(body=fake.text(),
  30. timestamp=fake.past_date(),
  31. author=u)
  32. db.session.add(p)
  33. db.session.commit()