本文整理汇总了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