Created
October 2, 2010 14:46
-
-
Save k0001/607691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(MSCRAP)k@del ~/q/mscrap_git/mscrap/mscrap % cat exporters.py | |
# -*- coding: utf8 -*- | |
from scrapy.contrib.exporter import JsonLinesItemExporter | |
class TypedJsonLinesItemExporter(JsonLinesItemExporter): | |
""" | |
Like JsonLinesItemExporter but each line adds the item type. | |
Example: | |
['LegisladorItem', {...LegisladorItem data...}] | |
""" | |
def export_item(self, item): | |
itemtype = item.__class__.__name__ | |
itemdict = dict(self._get_serialized_fields(item)) | |
self.file.write(self.encoder.encode([itemtype, itemdict]) + '\n') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment