def __add_book(self): print("\n") title = input("Introduceti titlul cartii: ") author = input("Introduceti autorul cartii: ") age = int(input("Introduceti anul publicarii cartii (aveti grija sa fie un numar ;): ")) price = float(input("Introduceti pretul cartii (aveti grija sa fie un numar ;): ")) new_book = Book(title, author, age, price) res = self.__service.add_book(new_book) if res == -1: print("\nCartea exista deja!\n") else: print("\nCartea a fost adaugata cu succes!\n")
def publish_ebooks(wallet: WalletWithTxAnchor, collection: Collection, publish_n_books: int = 1, max_books_per_block: int = 150, skip_to_textno: int = 1): """ Publishes Gutenberg books for a certain Collection :param wallet: Arweave wallet, used for signing and sending transactions :param collection: Collection already existing in the permaweb. Books will be linked to it. :param publish_n_books: Number of Gutenberg books to be published. Will skip those that have already been persisted. :param max_books_per_block: Maximum number of books per block. Please check the README for further reference on what a block represents. :param skip_to_textno: Starts publishing Gutenberg books from a specific id :raises Exception: If collection had not been signed, or sent """ if not collection.is_signed or not collection.is_sent: raise Exception( 'Collection must already exist in the permaweb before you can publish' ) preexisting_books = find_books_from_collection(collection.trusted_sources, collection.id) preexisting_textnos = _get_textno_set(preexisting_books) top_block, books_top_block = _get_block_information(preexisting_books) published_amount = 0 cur_id = skip_to_textno - 1 while published_amount < publish_n_books: cur_id += 1 if cur_id in preexisting_textnos: warnings.warn( "Book '%d' already published for this collection. Skipping" % cur_id) continue if not _is_public_domain(cur_id): continue if books_top_block > max_books_per_block: top_block += 1 books_top_block = 0 try: epub_uri = next(uri for uri in get_metadata('formaturi', cur_id) if uri.endswith("epub.noimages")) except StopIteration: warnings.warn("Could not find epub for textno '%d'" % cur_id) continue ebook = Book(epub_uri=epub_uri, wallet=wallet, collection=collection, block_number=top_block) ebook.add_extra_tag(TAG_TEXTNO, str(cur_id)) for label in METADATA_ARGS: metadata = get_metadata(label, cur_id) decoded_metadata = frozenset( [unidecode(metadata_field) for metadata_field in metadata]) ebook.add_metadata_tag(label, decoded_metadata) print("... ready to publish textno '%d' (in block '%d')" % (cur_id, top_block)) try: ebook.sign() ebook.send() except UnicodeEncodeError as e: warnings.warn( "Encoding exception while trying to send texto '%d', skipping. Details: '%s'" % (cur_id, str(e))) warnings.warn(" Book metadata details: '%s'" % str(ebook.metadata)) continue published_amount += 1 books_top_block += 1 print('Done publishing %d books' % published_amount)
def initialize_default_books(self): self.__books.append(Book("Ion", "Liviu Rebreanu", 1920, 20)) self.__books.append(Book("Moara cu noroc", "Ioan Slavici", 1881, 50)) self.__books.append( Book("Hronicul si cantecul varstelor", "Lucian Blaga", 1965, 120)), self.__books.append(Book("Hanu Ancutei", "Mihail Sadoveanu", 1928, 37))