Skip to content

Instantly share code, notes, and snippets.

@k0001
Created October 2, 2010 14:46
Show Gist options
  • Save k0001/607691 to your computer and use it in GitHub Desktop.
Save k0001/607691 to your computer and use it in GitHub Desktop.
(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