本文整理匯總了Python中book.Book.description方法的典型用法代碼示例。如果您正苦於以下問題:Python Book.description方法的具體用法?Python Book.description怎麽用?Python Book.description使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類book.Book
的用法示例。
在下文中一共展示了Book.description方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: by_title
# 需要導入模塊: from book import Book [as 別名]
# 或者: from book.Book import description [as 別名]
def by_title(self, title):
"""
Search for a book on OpenLibrary by title
@param title: the title to search for
@return: the raw data of all results
"""
title = title.replace(' ', '+').lower()
url = urllib.request.urlopen(self.search_url+'title='+title)
data = simplejson.load(url)['docs']
for result in data:
book = Book(0)
book.title = result['title']
try:
book.authors = ', '.join(result['author_name']) if isinstance(result['publisher'], list) else result['author_name']
except KeyError:
book.authors = "None"
try:
book.publisher = ', '.join(result['publisher']) if isinstance(result['publisher'], list) else result['publisher']
except KeyError:
book.publisher = "No publisher found."
try:
book.publ_year = result['first_publish_year']
except KeyError:
book.publ_year = 0
try:
book.description = ''.join(result['first_sentence'])
except KeyError:
book.description = "No description found."
yield book
示例2: _get_book_from_json_dict
# 需要導入模塊: from book import Book [as 別名]
# 或者: from book.Book import description [as 別名]
def _get_book_from_json_dict(self, data):
"""
Create a new Book instance based on a JSON dict.
@param data: a JSON dictionary
@return: a new Book instance (sans ISBN)
"""
publishers = ', '.join([self._get_publisher_from_json_dict(p) for p in data['publishers']])
authors = ', '.join([self._get_author_from_json_dict(a) for a in data['authors']])
book = Book(0) # better to create an object, even if there's no valid barcode yet
book.title = data.get('title', None)
book.publisher = publishers
book.authors = authors
book.pages = data.get('number_of_pages', None) # might cause issue, be careful.
book.publ_year = data.get('publish_date', None)
book.description = data.get('excerpts', None)
return book