
import json,os
from datetime import datetime
from scrapy.exporters import JsonLinesItemExporter

path = "downloads"


class OnlineparticipationdatasetPipeline(object):
    def process_item(self, item, spider):
        return item


class JsonWriterPipeline(object):

    def open_spider(self, spider):
        if not os.path.isdir(path):
            os.makedirs(path)
        self.file = open("downloads/items_"+spider.name+".json", 'wb')
        self.exporter = JsonLinesItemExporter(self.file, encoding='utf-8', ensure_ascii=False)
        self.exporter.start_exporting()

    def close_spider(self, spider):
        self.exporter.finish_exporting()
        self.file.close()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item


import json,os
from datetime import datetime
from scrapy.exporters import JsonLinesItemExporter

path = "downloads"


class OnlineparticipationdatasetPipeline(object):
    def process_item(self, item, spider):
        return item


class JsonWriterPipeline(object):

    def open_spider(self, spider):
        if not os.path.isdir(path):
            os.makedirs(path)
        self.file = open("downloads/items_"+spider.name+".json", 'wb')
        self.exporter = JsonLinesItemExporter(self.file, encoding='utf-8', ensure_ascii=False)
        self.exporter.start_exporting()

    def close_spider(self, spider):
        self.exporter.finish_exporting()
        self.file.close()

    def process_item(self, item, spider):
        item['date_time'] = item['date_time'].isoformat()
        self.exporter.export_item(item)
        return item

Save datetime in JSON as ISO
Save datetime in JSON as ISO

  
  import json,os
  from datetime import datetime
  from scrapy.exporters import JsonLinesItemExporter
  
  path = "downloads"
  
  
  class OnlineparticipationdatasetPipeline(object):
      def process_item(self, item, spider):
          return item
  
  
  class JsonWriterPipeline(object):
  
      def open_spider(self, spider):
          if not os.path.isdir(path):
              os.makedirs(path)
          self.file = open("downloads/items_"+spider.name+".json", 'wb')
          self.exporter = JsonLinesItemExporter(self.file, encoding='utf-8', ensure_ascii=False)
          self.exporter.start_exporting()
  
      def close_spider(self, spider):
          self.exporter.finish_exporting()
          self.file.close()
  
      def process_item(self, item, spider):
+         item['date_time'] = item['date_time'].isoformat()
          self.exporter.export_item(item)
          return item
  
Save datetime in JSON as ISO
## Code Before:

import json,os
from datetime import datetime
from scrapy.exporters import JsonLinesItemExporter

path = "downloads"


class OnlineparticipationdatasetPipeline(object):
    def process_item(self, item, spider):
        return item


class JsonWriterPipeline(object):

    def open_spider(self, spider):
        if not os.path.isdir(path):
            os.makedirs(path)
        self.file = open("downloads/items_"+spider.name+".json", 'wb')
        self.exporter = JsonLinesItemExporter(self.file, encoding='utf-8', ensure_ascii=False)
        self.exporter.start_exporting()

    def close_spider(self, spider):
        self.exporter.finish_exporting()
        self.file.close()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item

## Instruction:
Save datetime in JSON as ISO
## Code After:

import json,os
from datetime import datetime
from scrapy.exporters import JsonLinesItemExporter

path = "downloads"


class OnlineparticipationdatasetPipeline(object):
    def process_item(self, item, spider):
        return item


class JsonWriterPipeline(object):

    def open_spider(self, spider):
        if not os.path.isdir(path):
            os.makedirs(path)
        self.file = open("downloads/items_"+spider.name+".json", 'wb')
        self.exporter = JsonLinesItemExporter(self.file, encoding='utf-8', ensure_ascii=False)
        self.exporter.start_exporting()

    def close_spider(self, spider):
        self.exporter.finish_exporting()
        self.file.close()

    def process_item(self, item, spider):
        item['date_time'] = item['date_time'].isoformat()
        self.exporter.export_item(item)
        return item
