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
评论列表
文章目录