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


Python LibraryDatabase.set_metadata方法代码示例

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


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

示例1: __init__

# 需要导入模块: from calibre.db.legacy import LibraryDatabase [as 别名]
# 或者: from calibre.db.legacy.LibraryDatabase import set_metadata [as 别名]
class App:
    def __init__(self, library_path):
        self.fmt = "[%6s] [%4d/%4d] [ISBN=%13s] [Title=%s]"
        if os.path.isfile(library_path):
            library_path = os.path.dirname(library_path)
        self.db = LibraryDatabase(os.path.expanduser(library_path))

    def log_error(self, msg):
        print "\033[1;31;40m%s\033[0m" % msg

    def log_succ(self, msg):
        print "\033[1;32;40m%s\033[0m" % msg

    def get_baike_metadata(self, title):
        from baidubaike import Page

        try: baike = Page(title)
        except: return None

        info = baike.get_info()
        print "\n".join( "%s:\t%s" % v for v in info.items())
        mi = Metadata(info['title'])
        plat = info.get(u'首发网站', None)
        if not plat:
            plat = info.get(u'首发状态', "网络小说平台")
        plat = plat.replace(u'首发', '')
        mi.publisher = info.get(u'连载平台', plat)
        mi.authors   = [info[u'作者']]
        mi.isbn      = '0000000000001'
        mi.tags      = baike.get_tags()
        mi.pubdate   = datetime.datetime.now()
        mi.timestamp = datetime.datetime.now()
        mi.comments  = baike.get_summary()
        if u'完结' in info.get(u'连载状态', ""):
            day = re.findall('\d*-\d*-\d*', info[u'连载状态'])
            try: mi.pubdate = datetime.datetime.strptime(day[0], '%Y-%m-%d')
            except: pass
        return mi

    def do_book_update(self, book_id):
        book_id = int(book_id)
        mi = self.db.get_metadata(book_id, index_is_id=True)
        #if not mi.comments or mi.comments == "None":
            #logging.error("\n\n[%s]\n=================\nCalibre Metadata:\n%s\n===========" % (mi.title, mi))

        title = mi.title
        mi.title = title.split("(")[0].split("(")[0].strip()
        #douban_mi = douban.select_douban_metadata(mi)
        douban_mi = douban.get_douban_metadata(mi)
        if not douban_mi:
            try:
                douban_mi = self.get_baike_metadata(mi.title)
            except Exception as e:
                logging.error(e)
                pass

        if not douban_mi:
            self.log_error(self.fmt % ("404", book_id, self.total, "", title))
            return

        if mi.cover_data[0]: douban_mi.cover_data = None
        mi.smart_update(douban_mi, replace_metadata=True)
        self.db.set_metadata(book_id, mi)
        self.log_succ(self.fmt % ("Update", book_id, self.total, douban_mi.isbn, mi.title))

    def update_all_by_isbn(self):
        ids = self.db.search_getting_ids('', None)
        self.total = max(ids)
        books = self.db.get_data_as_dict(ids=ids)

        need_update = []
        for book in books:
            if book['comments']: continue
            if book['tags']: continue
            if book['isbn']: continue
            if int(book['id']) < 6722: continue
            print self.fmt%("Todo", book['id'], self.total, book['isbn'], book['title'])
            self.do_book_update(book['id'])
开发者ID:talebook,项目名称:calibre-webserver,代码行数:80,代码来源:tools.py


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