def generate_post(func_author): return Post( title=lorem_ipsum.title(), body=lorem_ipsum.paragraphs(), created=date.date(), author=func_author(), )
def generate_fake(count=100): from random import seed, randint from forgery_py import lorem_ipsum, name from sqlalchemy.exc import IntegrityError seed() author_count = Author.query.count() reading_levels = ['Teen', 'Children', 'Adult'] genres = ['Comic', 'Autobiography', 'Biography', 'Crime/Detective', 'Fantasy', 'Historical Fiction', 'Magical Realism', 'Mystery', 'Mythopoeia', 'Poetry', 'Realistic Fiction', 'Scientific Fiction', 'Short Story', 'Textbook', 'Thriller', 'Western'] for i in range(count): #needs to be 13 length isbn = str(randint(10000, 99999)) + str(randint(10000, 99999)) + str(randint(100, 999)) bk = BookDetails(isbn=isbn, title=lorem_ipsum.title(), reading_level=reading_levels[randint(0,2)], publisher=name.company_name(), genre=genres[randint(0,len(genres)-1)]) if author_count > 0: a1 = Author.query.offset(randint(0, author_count - 1)).first() a2 = Author.query.offset(randint(0, author_count - 1)).first() while(a1 == a2): a2 = Author.query.offset(randint(0, author_count - 1)).first() bk.authors.append(a1) bk.authors.append(a2) try: db.session.add(bk) db.session.commit() except IntegrityError: db.session.rollback()
def generate_fake_title(): from forgery_py import lorem_ipsum for p in Post.query.all(): p.title = lorem_ipsum.title() db.session.add(p) db.session.commit()
def generate_article(func_author): return Article(title=lorem_ipsum.title(), body=lorem_ipsum.paragraphs(), created_time=date.date(past=True), author=func_author())
def generate_post(func_author): return Post(title=lorem_ipsum.title(), body=lorem_ipsum.paragraphs(), created=date.date(), author=func_author())