if len(title) >= 300: title = title[0:295] + '...' books = '{}\n'.format(cnt) books += 'Book Title: {}\n'.format(title) books += 'Pages: {}\n'.format(pages) books += 'Price: {}\n'.format(price) books += 'Rating: {}\n'.format(rating) books += 'Publisher: {}\n'.format(publisher) books += 'Published Date: {}\n'.format(published_date.strftime("%Y-%m-%d")) book = Book() book.book_title = title book.pages = pages book.price = price book.rating = rating book.publisher_id = publisher book.published_date = published_date author_id = [random.randint(1, 1572)] if cnt % 17 == 0: for i in range(1, 3): author_id.append(random.randint(1, 1572)) if cnt % 29 == 0: for i in range(1, 4): author_id.append(random.randint(1, 1572)) if cnt % 71 == 0: for i in range(1, 5):