Beispiel #1
0
    async def handler_content(self, res, chapter: Chapter):
        content = self.parser(res)
        logging.info('处理<<{}>>{},正文信息:{}...'.format(chapter.book, chapter,
                                                    content[:15]))

        if chapter.book_type == BOOK_TYPE_DESC.Comic:
            imgs = []
            for key in content.keys():
                imgs.insert(int(key), content[key])
            img_objs = await self.save_image(imgs,
                                             IMAGE_TYPE_DESC.CHAPER_CONTENT,
                                             self.headers)
            # 如果能获取到所有img对象则保存
            if len(img_objs) and None not in img_objs:
                content = img_objs

        try:
            chapter.save_content(content)
            chapter.active = True
            chapter.save()
        except OSError:
            logging.error('处理<<{}>>单章节正文信息 失败 : {}'.format(
                chapter.book, chapter))
            chapter.active = False
            chapter.save()
            pass
Beispiel #2
0
    def handler_content(self, content, chapter: Chapter):
        logging.info("处理--{}--<<{}>>{},正文信息:{}...".format(
            self.wait_done, chapter.book, chapter, content[:10]))
        if chapter.book_type == BOOK_TYPE_DESC.Comic:
            imgs = []
            for key in content.keys():
                imgs.insert(int(key), content[key])
            img_objs = self.save_image(imgs, IMAGE_TYPE_DESC.CHAPER_CONTENT,
                                       self.headers)
            # 如果能获取到所有img对象则保存
            if len(img_objs) and None not in img_objs:
                content = img_objs

        try:
            if not content:
                raise OSError
            chapter.save_content(content)
            chapter.active = True
            chapter.save()
        except OSError:
            logging.error("处理<<{}>>单章节正文信息 失败 : {}".format(
                chapter.book, chapter))
            chapter.active = False
            chapter.save()
            pass