old_contents: import datetime
  
  import gridfs
  import pymongo
  
  from scrapy.pipelines.files import FilesPipeline
  from scrapy.utils.misc import md5sum
  
  
  class GridFSFilesStorage(object):
      """MongoDB GridFS storage.
      Store files in GridFS and returns their ObjectId.
      Check if file exists based on file guid generated by pipeline"""
  
      def __init__(self, uri):
          client = pymongo.MongoClient(uri)
          self.db = client.myscrapy
          self.fs = gridfs.GridFS(self.db)
  
      def persist_file(self, file_guid, buf, info, meta=None, headers=None):
          """Save the file to GridFS and return it's ObjectId"""
  
          grid_id = self.fs.put(buf, scrapy_guid=file_guid)
          return grid_id
  
      def stat_file(self, file_guid, info):
          """Check if file exists based on file guid generated by the scrapy pipeline"""
  
          pdf = self.fs.find_one({'scrapy_guid': file_guid})
          epoch = datetime.datetime.utcfromtimestamp(0)
          last_modified = (pdf.upload_date - epoch).total_seconds()
          checksum = md5sum(pdf)
          return {'last_modified': last_modified, 'checksum': checksum, 'mongo_objectid': pdf._id}
  
  
  class GridFSFilesPipeline(FilesPipeline):
      """
      An extension of FilesPipeline that store files in MongoDB GridFS.
      Is using a guid to check if the file exists in GridFS and MongoDB ObjectId to reference the file with item.
      FilesPipeline was using a single variable 'path' for reference and identification.
      guid is used in MongoGridFSFilesPipeline because the pipeline needs a unique identifier generated based on file URL.
      MongoGridFSFilesPipeline is using ObjectId to reference the file because it's the primary key.
      """
  
      @classmethod
      def from_settings(cls, settings):
          """Override to use store_uri = MONGO_URI"""
  
          store_uri = settings['MONGO_URI']
          return cls(store_uri, settings=settings)
  
      def _get_store(self, uri):
          """Override to use MongoGridFSFilesStorage as singele storage option"""
  
      def media_to_download(self, request, info):
          """Override to include in the returned result mongo object id and file_guid instead of file_path and filename"""
  
      def media_downloaded(self, response, request, info):
          """Override to include in the returned result mongo object id and file_guid instead of file_path and filename"""
  
      def file_downloaded(self, response, request, info):
          """Override to return also the mongo object id along with checksum"""
  
      def file_guid(self, request, response=None, info=None):
          """Renamed and modify file_path to file_guid. In mongo DB the path to file is mongo id. In FilesPipeline path
          was used as identifier and localization"""
  
      def filename(self, request):
          """Return the original filename"""
  
new_contents: import datetime
  
  import gridfs
  import pymongo
  
  from scrapy.pipelines.files import FilesPipeline
  from scrapy.utils.misc import md5sum
  
  
  class GridFSFilesStorage(object):
      """MongoDB GridFS storage.
      Store files in GridFS and returns their ObjectId.
      Check if file exists based on file guid generated by pipeline"""
  
      def __init__(self, uri):
          client = pymongo.MongoClient(uri)
          self.db = client.myscrapy
          self.fs = gridfs.GridFS(self.db)
  
      def persist_file(self, file_guid, buf, info, meta=None, headers=None):
          """Save the file to GridFS and return it's ObjectId"""
  
          grid_id = self.fs.put(buf, scrapy_guid=file_guid)
          return grid_id
  
      def stat_file(self, file_guid, info):
          """Check if file exists based on file guid generated by the scrapy pipeline"""
  
          pdf = self.fs.find_one({'scrapy_guid': file_guid})
          epoch = datetime.datetime.utcfromtimestamp(0)
          last_modified = (pdf.upload_date - epoch).total_seconds()
          checksum = md5sum(pdf)
          return {'last_modified': last_modified, 'checksum': checksum, 'mongo_objectid': pdf._id}
  
  
  class GridFSFilesPipeline(FilesPipeline):
      """
      An extension of FilesPipeline that store files in MongoDB GridFS.
      Is using a guid to check if the file exists in GridFS and MongoDB ObjectId to reference the file with item.
      FilesPipeline was using a single variable 'path' for reference and identification.
      guid is used in MongoGridFSFilesPipeline because the pipeline needs a unique identifier generated based on file URL.
      MongoGridFSFilesPipeline is using ObjectId to reference the file because it's the primary key.
      """
  
      @classmethod
      def from_settings(cls, settings):
          """Override to use store_uri = MONGO_URI"""
  
          store_uri = settings['MONGO_URI']
          return cls(store_uri, settings=settings)
  
      def _get_store(self, uri):
          """Override to use MongoGridFSFilesStorage as singele storage option"""
          store_cls = GridFSFilesStorage
          return store_cls(uri)
  
      def media_to_download(self, request, info):
          """Override to include in the returned result mongo object id and file_guid instead of file_path and filename"""
  
      def media_downloaded(self, response, request, info):
          """Override to include in the returned result mongo object id and file_guid instead of file_path and filename"""
  
      def file_downloaded(self, response, request, info):
          """Override to return also the mongo object id along with checksum"""
  
      def file_guid(self, request, response=None, info=None):
          """Renamed and modify file_path to file_guid. In mongo DB the path to file is mongo id. In FilesPipeline path
          was used as identifier and localization"""
  
      def filename(self, request):
          """Return the original filename"""
  
subject: create _get_store