store_text.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:gransk 作者: pcbje 项目源码 文件源码
def consume(self, doc, payload):
    """
    Write text to target directory, using a combination of filename and file
    ID as path.

    :param doc: Document object.
    :param payload: File pointer beloning to document.
    :type doc: ``gransk.core.document.Document``
    :type payload: ``file``
    """
    new_filename = '%s-%s' % \
      (doc.docid[0:8], document.secure_path(os.path.basename(doc.path)))

    if not os.path.exists(self.root):
      os.makedirs(self.root)

    new_path = os.path.join(self.root, new_filename)

    with io.open(new_path, 'w', encoding='utf-8') as out:
      out.write(doc.text)

    doc.meta['text_file'] = new_path
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号