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 compose_book(self,r): book = Book() book.id = r['bid'] book.isbn10 = r['isbn10'] book.isbn13 = r['isbn13'] book.title = r['title'] book.subtitle = r['subtitle'] book.author = r['author'] book.translators = r['translators'] book.publisher = r['publisher'] book.pubdate = r['pubdate'] book.price = r['price'] book.pages = r['pages'] book.update_time = r['update_time'] book.create_time = r['create_time'] book.quantity = r['quantity'] book.series = r['series'] book.keywords = r['keywords'] book.summary = r['summary'] book.status = r['status'] book.transtr = book._transtr() return book
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))
def startDocument(self): #print "Here....." self.book = Book()
class SimpleHandler(sax.ContentHandler): """simple sax handler to parse the xml from douban""" def __init__(self): self.book=None self.buffer = [] self.itemName = "" self.pPages = re.compile("([0-9]+)\\D*") self.pPrice = re.compile("([0-9]*\\.[0-9]{0,2})(\\D*)") def startDocument(self): #print "Here....." self.book = Book() def startElement(self,name, attrs): self.buffer = [] #print "start:"+name if "db:attribute" == name : self.itemName = attrs.getValue('name') def endElement(self,name): if "db:attribute" == name : #print "%d,%s" %(len(self.buffer),"".join(self.buffer)) if "isbn10" ==self.itemName : self.book.isbn10 = "".join(self.buffer) elif "isbn13" ==self.itemName : self.book.isbn13 = "".join(self.buffer) elif "title" ==self.itemName : self.book.title = "".join(self.buffer) elif "subtitle" ==self.itemName : self.book.subtitle = "".join(self.buffer) elif "author" ==self.itemName : self.book.author = "".join(self.buffer) elif "publisher" ==self.itemName : self.book.publisher = "".join(self.buffer) elif "pubdate" == self.itemName : self.book.pubdate = "".join(self.buffer) elif "format" ==self.itemName : self.book.format = "".join(self.buffer) elif "binding" == self.itemName : self.book.binding = "".join(self.buffer) elif "series" == self.itemName : self.book.series = "".join(self.buffer) elif "keywords" == self.itemName : self.book.keywords = "".join(self.buffer) elif "author-intro" == self.itemName : self.book.authorintro = "".join(self.buffer) #there maybe multiple translators elif "translator" == self.itemName : self.book.translators.append("".join(self.buffer)) elif "quantity" == self.itemName : self.book.quantity = "".join(self.buffer) elif "pages" == self.itemName : self.book.pages = 0 matcher = self.pPages.match("".join(self.buffer)) if matcher : self.book.pages = int(matcher.group(1)) elif "price" == self.itemName : self.book.price = 0.0 matcher = self.pPrice.match("".join(self.buffer)) if matcher : self.book.price = float(matcher.group(1)) elif 'summary' == name : self.book.summary = "".join(self.buffer) def characters(self,content): self.buffer.append(content.strip()) def getresult(self): self.book.transtr = self.book._transtr() return self.book