def pull_books(self, N_BOOKS = None): books = [] if N_BOOKS is None: for p in Publisher.enlist(): books += list(p.books) self.shelf = Warehouse(books * 5) return else: from itertools import chain all_books = list(chain.from_iterable([list(p.books) for p in Publisher.enlist()])) self.shelf = Warehouse([random.choice(all_books) for _ in range(N_BOOKS)])
def order(self, customer, orders : []): book_list = [] for order in orders: # Author if hasattr(order, 'surname'): # searching most recent release among all publishers publishers = Publisher.enlist() # all existing publishers most_recent = [] for p in publishers: books = p.booksByAuthor(order) if books: most_recent.append(books[0]) # the most recent book: book = list(sorted(most_recent, key=lambda x: x.uptime()))[0] book = Book.reprice(book, self.get_real_price(book)) book_list.append(book) else: # Book: book_list.append(Book.reprice(order, self.get_real_price(order))) order = Order(self, customer, book_list) # if the orders are processed simultaneously & automatically if self.AUTO_BUY: if not order: # order cannot be executed # and books need to be printed and delivered # self.orders is a queue for those orders. self.orders.append(order) else: # Buy it! # Order is executed order.execute() return order
def pick_pub(): pub = random.choice( Publisher.enlist()) if Publisher.enlist() else Publisher( 'SomePub', []) return pub