当前位置: 首页>>代码示例>>Python>>正文


Python Book.authors方法代码示例

本文整理汇总了Python中book.Book.authors方法的典型用法代码示例。如果您正苦于以下问题:Python Book.authors方法的具体用法?Python Book.authors怎么用?Python Book.authors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在book.Book的用法示例。


在下文中一共展示了Book.authors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: by_title

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import authors [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
开发者ID:bjschafer,项目名称:pyberry,代码行数:34,代码来源:lookup.py

示例2: _get_book_from_json_dict

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import authors [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
开发者ID:bjschafer,项目名称:pyberry,代码行数:19,代码来源:lookup.py


注:本文中的book.Book.authors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。