def generate_fake(count=100): from sqlalchemy.exc import IntegrityError from random import seed from forgery_py import name, date, internet, address, personal seed() for i in range(count): p = Person(name.first_name(), name.last_name(), date.date(), personal.gender(), address.phone(), internet.email_address(), address.street_address(), address.city(), address.state_abbrev(), address.zip_code()) db.session.add(p) try: db.session.commit() except IntegrityError: db.session.rollback()
def generate_fake(count=100): from sqlalchemy.exc import IntegrityError from random import seed, randint from forgery_py import name, internet, address seed() reading_levels = ['Teen', 'Adult', 'Children'] for i in range(count): current_reading_level = reading_levels[randint(0,2)] rl = ReadingLevels.query.filter(ReadingLevels.reading_level == current_reading_level).first() c = Client(name.full_name(), address.phone(), internet.email_address(), address.street_address(), address.city(), address.state_abbrev(), address.zip_code(), current_reading_level, name.last_name()) rl.clients.append(c) try: db.session.add(c) db.session.commit() except IntegrityError: db.session.rollback()
def gene_users(count=100): from random import seed, randint from sqlalchemy.exc import IntegrityError gender = ('男', '女', '不告诉你') seed() for i in range(count): fake_user = User() fake_user.username = internet.user_name(True) fake_user.email = fake_user.username + '@test.com' fake_user.password = '******' fake_user.name = name.full_name() fake_user.about_me = lorem_ipsum.sentence()[0:99] fake_user.timestamp = date.date(past=True) fake_user.birthday = date.date(past=True) fake_user.gender = gender[randint(0, 2)] fake_user.phone = address.phone() fake_user.address = address.street_address() fake_user.id_number = ''.join([str(randint(0, 9)) for i in range(18)]) db.session.add(fake_user) try: db.session.commit() except IntegrityError: db.session.rollback()