コード例 #1
0
ファイル: __init__.py プロジェクト: xiaoch2004/ZhihuSpider
    def start(cls, management, table):
        table.show_interface(management)

        if management.name == 'Video':
            # todo 设置差错处理
            meta = management.parse_data(management.data)
            management.download_video(meta, process_bar=table.download_process)
            table.close()
            return

        if management.name in ('Answer', 'Article'):
            # todo 设置差错处理
            meta = management.parse_data(management.data)
            if config.get('output_html'):
                Document.item2html(meta, config.get('css_output'),
                                   config.get('remove_media'))

            if config.get('output_md'):
                Document.item2md(meta, config.get('remove_media'))

            if config.get('download_image'):
                management.download_images(meta.content, table.image_process)

            table.close()
            return

        if management.name in ('Question', 'Column', 'Collection'):
            # todo 设置差错处理

            # 当前模式下无法预知图片总数量,所以只要下载图片就启用 DoubleProcessBar
            table.double_process_bar = config.get('download_image')

            for data in management:

                meta = management.parse_data(data)

                try:
                    assert meta is not None
                except AssertionError:
                    continue

                if config.get('output_html'):
                    Document.item2html(meta, config.get('css_output'),
                                       config.get('remove_media'))

                if config.get('output_md'):
                    Document.item2md(meta, config.get('remove_media'))

                if config.get('output_html') or config.get('output_md'):
                    table.text_process(management.totals)

                if config.get('download_image'):
                    management.download_images(meta.content,
                                               table.image_process)

            table.close()
            return
コード例 #2
0
 def handle_data(self, data):
     meta, cont = self.parse_data(data)
     Document.make_document(meta, cont)