示例#1
0
 def __init__(self, _db, api_key=None, do_get=None, metadata_client=None):
     self._db = _db
     self.api_key = api_key
     self.do_get = do_get or Representation.simple_http_get
     if not metadata_client:
         metadata_client = MetadataWranglerOPDSLookup.from_config(self._db)
     self.metadata_client = metadata_client
示例#2
0
    def __init__(self, collection, upload_client=None, **kwargs):
        _db = Session.object_session(collection)
        self.upload_client = upload_client or MetadataWranglerOPDSLookup.from_config(
            _db, collection=collection)

        super(MetadataUploadCoverageProvider,
              self).__init__(collection, **kwargs)
        if not self.upload_client.authenticated:
            raise CannotLoadConfiguration(
                "Authentication for the Library Simplified Metadata Wrangler "
                "is not set up. You can't upload metadata without authenticating."
            )
示例#3
0
    def __init__(self, collection, lookup_client=None, **kwargs):
        _db = Session.object_session(collection)
        lookup_client = lookup_client or MetadataWranglerOPDSLookup.from_config(
            _db, collection=collection)

        super(MetadataWranglerCoverageProvider,
              self).__init__(collection, lookup_client, **kwargs)
        if not self.lookup_client.authenticated:
            self.log.warn(
                "Authentication for the Library Simplified Metadata Wrangler "
                "is not set up. You can still use the metadata wrangler, but "
                "it will not know which collection you're asking about.")
示例#4
0
 def __init__(self, _db, collection, lookup=None):
     super(MetadataWranglerCollectionMonitor,
           self).__init__(_db, collection)
     self.lookup = lookup or MetadataWranglerOPDSLookup.from_config(
         self._db, collection=collection)
     self.importer = OPDSImporter(
         self._db,
         self.collection,
         data_source_name=DataSource.METADATA_WRANGLER,
         metadata_client=self.lookup,
         map_from_collection=True,
     )
示例#5
0
 def __init__(self, _db, collection, lookup=None):
     super(MetadataWranglerCollectionMonitor, self).__init__(
         _db, collection
     )
     self.lookup = lookup or MetadataWranglerOPDSLookup.from_config(
         self._db, collection=collection
     )
     self.importer = OPDSImporter(
         self._db, self.collection,
         data_source_name=DataSource.METADATA_WRANGLER,
         metadata_client=self.lookup, map_from_collection=True,
     )
示例#6
0
 def __init__(self, _db, api_key=None, do_get=None, metadata_client=None):
     self.log = logging.getLogger("NYT API")
     self._db = _db
     if not api_key:
         raise CannotLoadConfiguration("No NYT API key is specified")
     self.api_key = api_key
     self.do_get = do_get or Representation.simple_http_get
     if not metadata_client:
         try:
             metadata_client = MetadataWranglerOPDSLookup.from_config(
                 self._db)
         except CannotLoadConfiguration, e:
             self.log.error(
                 "Metadata wrangler integration is not configured, proceeding without one."
             )
示例#7
0
 def __init__(self, collection, lookup_client=None, **kwargs):
     """Since we are processing a specific collection, we must be able to
     get an _authenticated_ metadata wrangler lookup client for the
     collection.
     """
     _db = Session.object_session(collection)
     lookup_client = lookup_client or MetadataWranglerOPDSLookup.from_config(
         _db, collection=collection)
     super(BaseMetadataWranglerCoverageProvider,
           self).__init__(collection, lookup_client, **kwargs)
     if not self.lookup_client.authenticated:
         raise CannotLoadConfiguration(
             "Authentication for the Library Simplified Metadata Wrangler "
             "is not set up. Without this, there is no way to register "
             "your identifiers with the metadata wrangler.")
示例#8
0
 def __init__(self, _db, api_key=None, do_get=None, metadata_client=None):
     self.log = logging.getLogger("NYT API")
     self._db = _db
     if not api_key:
         raise CannotLoadConfiguration("No NYT API key is specified")
     self.api_key = api_key
     self.do_get = do_get or Representation.simple_http_get
     if not metadata_client:
         try:
             metadata_client = MetadataWranglerOPDSLookup.from_config(
                 self._db
             )
         except CannotLoadConfiguration, e:
             self.log.error(
                 "Metadata wrangler integration is not configured, proceeding without one."
             )
示例#9
0
 def __init__(self, collection, lookup_client=None, **kwargs):
     """Since we are processing a specific collection, we must be able to
     get an _authenticated_ metadata wrangler lookup client for the
     collection.
     """
     _db = Session.object_session(collection)
     lookup_client = lookup_client or MetadataWranglerOPDSLookup.from_config(
         _db, collection=collection
     )
     super(BaseMetadataWranglerCoverageProvider, self).__init__(
         collection, lookup_client, **kwargs
     )
     if not self.lookup_client.authenticated:
         raise CannotLoadConfiguration(
             "Authentication for the Library Simplified Metadata Wrangler "
             "is not set up. Without this, there is no way to register "
             "your identifiers with the metadata wrangler."
         )
示例#10
0
    def __init__(self,
                 _db,
                 collection,
                 api_class=Axis360API,
                 metadata_client=None):
        super(Axis360CirculationMonitor, self).__init__(_db, collection)
        if isinstance(api_class, Axis360API):
            # Use a preexisting Axis360API instance rather than
            # creating a new one.
            self.api = api_class
        else:
            self.api = api_class(collection)
        if not metadata_client:
            metadata_client = MetadataWranglerOPDSLookup.from_config(
                _db, collection=collection)

        self.batch_size = self.DEFAULT_BATCH_SIZE
        self.metadata_client = metadata_client
        self.bibliographic_coverage_provider = (
            Axis360BibliographicCoverageProvider(collection,
                                                 api_class=self.api))
示例#11
0
 def __init__(self, metadata_web_app_url=None):
     if metadata_web_app_url:
         self.lookup = MetadataWranglerOPDSLookup(metadata_web_app_url)
     else:
         self.lookup = MetadataWranglerOPDSLookup.from_config(_db)
示例#12
0
class CreateWorksForIdentifiersScript(Script):

    """Do the bare minimum to associate each Identifier with an Edition
    with title and author, so that we can calculate a permanent work
    ID.
    """
    to_check = [Identifier.OVERDRIVE_ID, Identifier.THREEM_ID,
                Identifier.GUTENBERG_ID]
    BATCH_SIZE = 100
    name = "Create works for identifiers"

    def __init__(self, metadata_web_app_url=None):
        if metadata_web_app_url:
            self.lookup = MetadataWranglerOPDSLookup(metadata_web_app_url)
        else:
            self.lookup = MetadataWranglerOPDSLookup.from_config(_db)

    def run(self):

        # We will try to fill in Editions that are missing
        # title/author and as such have no permanent work ID.
        #
        # We will also try to create Editions for Identifiers that
        # have no Edition.

        either_title_or_author_missing = or_(
            Edition.title == None,
            Edition.sort_author == None,
        )
        edition_missing_title_or_author = self._db.query(Identifier).join(
            Identifier.primarily_identifies).filter(
                either_title_or_author_missing)

        no_edition = self._db.query(Identifier).filter(
            Identifier.primarily_identifies==None).filter(
                Identifier.type.in_(self.to_check))

        for q, descr in (
                (edition_missing_title_or_author,
                 "identifiers whose edition is missing title or author"),
                (no_edition, "identifiers with no edition")):
            batch = []
            self.log.debug("Trying to fix %d %s", q.count(), descr)
            for i in q:
                batch.append(i)
                if len(batch) >= self.BATCH_SIZE:
                    self.process_batch(batch)
                    batch = []

    def process_batch(self, batch):
        response = self.lookup.lookup(batch)

        if response.status_code != 200:
            raise Exception(response.text)
            
        content_type = response.headers['content-type']
        if content_type != OPDSFeed.ACQUISITION_FEED_TYPE:
            raise Exception("Wrong media type: %s" % content_type)

        importer = OPDSImporter(
            self._db, response.text,
            overwrite_rels=[Hyperlink.DESCRIPTION, Hyperlink.IMAGE])
        imported, messages_by_id = importer.import_from_feed()
        self.log.info("%d successes, %d failures.", 
                      len(imported), len(messages_by_id))
        self._db.commit()
示例#13
0
 def __init__(self, _db, collection, lookup=None):
     super(MetadataWranglerCollectionUpdateMonitor,
           self).__init__(_db, collection)
     self.lookup = lookup or MetadataWranglerOPDSLookup.from_config(
         self._db, collection=collection)