Ejemplo n.º 1
0
 def __init__(self, _db, interval_seconds=None):
     super(SetDeliveryMechanismMonitor, self).__init__(
         _db,
         "20151002 migration - Correct medium of mislabeled audiobooks",
         interval_seconds,
         batch_size=100)
     self.overdrive = OverdriveAPI(_db)
     self.threem = ThreeMAPI(_db)
Ejemplo n.º 2
0
 def __init__(self, _db, interval_seconds=None):
     super(SetDeliveryMechanismMonitor, self).__init__(
         _db,
         "20150929 migration - Set delivery mechanism for 3M books",
         interval_seconds,
         batch_size=10)
     self.api = ThreeMAPI(_db)
     self.metadata_client = SimplifiedOPDSLookup(
         "http://metadata.alpha.librarysimplified.org/")
Ejemplo n.º 3
0
class SetDeliveryMechanismMonitor(IdentifierSweepMonitor):
    def __init__(self, _db, interval_seconds=None):
        super(SetDeliveryMechanismMonitor, self).__init__(
            _db,
            "20151002 migration - Correct medium of mislabeled audiobooks",
            interval_seconds,
            batch_size=100)
        self.overdrive = OverdriveAPI(_db)
        self.threem = ThreeMAPI(_db)

    types = [
        Identifier.THREEM_ID, Identifier.OVERDRIVE_ID, Identifier.AXIS_360_ID
    ]

    content_types = [
        "application/epub+zip", "application/pdf", "Kindle via Amazon",
        "Streaming Text"
    ]

    def identifier_query(self):
        qu = self._db.query(Identifier).join(Identifier.licensed_through).join(
            LicensePool.delivery_mechanisms).join(
                LicensePoolDeliveryMechanism.delivery_mechanism).filter(
                    Identifier.type.in_(
                        self.types)).filter(~DeliveryMechanism.content_type.
                                            in_(self.content_types))
        return qu

    def process_identifier(self, identifier):
        # What is the correct medium?
        correct_medium = None
        lp = identifier.licensed_through
        for lpdm in lp.delivery_mechanisms:
            correct_medium = lpdm.delivery_mechanism.implicit_medium
            if correct_medium:
                break
        if not correct_medium and identifier.type == Identifier.OVERDRIVE_ID:
            content = self.overdrive.metadata_lookup(identifier)
            metadata = OverdriveRepresentationExtractor.book_info_to_metadata(
                content)
            correct_medium = metadata.medium

        if not correct_medium and identifier.type == Identifier.THREEM_ID:
            metadata = self.threem.bibliographic_lookup(identifier)
            correct_medium = metadata.medium

        if not correct_medium:
            set_trace()

        if lp.edition.medium != correct_medium:
            print "%s is actually %s, not %s" % (
                lp.edition.title, correct_medium, lp.edition.medium)
            lp.edition.medium = correct_medium or Edition.BOOK_MEDIUM
class SetDeliveryMechanismMonitor(IdentifierSweepMonitor):

    def __init__(self, _db, interval_seconds=None):
        super(SetDeliveryMechanismMonitor, self).__init__(
            _db, "20151002 migration - Correct medium of mislabeled audiobooks",
            interval_seconds, batch_size=100)
        self.overdrive = OverdriveAPI(_db)
        self.threem = ThreeMAPI(_db)

    types = [Identifier.THREEM_ID, Identifier.OVERDRIVE_ID,
             Identifier.AXIS_360_ID]

    content_types = ["application/epub+zip", "application/pdf",
                     "Kindle via Amazon", "Streaming Text"]

    def identifier_query(self):
        qu = self._db.query(Identifier).join(
                Identifier.licensed_through).join(
                    LicensePool.delivery_mechanisms).join(
                        LicensePoolDeliveryMechanism.delivery_mechanism).filter(
                    Identifier.type.in_(self.types)).filter(
                        ~DeliveryMechanism.content_type.in_(self.content_types)
                    )
        return qu

    def process_identifier(self, identifier):
        # What is the correct medium?
        correct_medium = None
        lp = identifier.licensed_through
        for lpdm in lp.delivery_mechanisms:
            correct_medium = lpdm.delivery_mechanism.implicit_medium
            if correct_medium:
                break
        if not correct_medium and identifier.type==Identifier.OVERDRIVE_ID:
            content = self.overdrive.metadata_lookup(identifier)
            metadata = OverdriveRepresentationExtractor.book_info_to_metadata(content)
            correct_medium = metadata.medium

        if not correct_medium and identifier.type==Identifier.THREEM_ID:
            metadata = self.threem.bibliographic_lookup(identifier)
            correct_medium = metadata.medium

        if not correct_medium:
            set_trace()

        if lp.edition.medium != correct_medium:
            print "%s is actually %s, not %s" % (lp.edition.title, correct_medium, lp.edition.medium)
            lp.edition.medium = correct_medium or Edition.BOOK_MEDIUM
Ejemplo n.º 5
0
class SetDeliveryMechanismMonitor(IdentifierSweepMonitor):
    def __init__(self, _db, interval_seconds=None):
        super(SetDeliveryMechanismMonitor, self).__init__(
            _db,
            "20150929 migration - Set delivery mechanism for 3M books",
            interval_seconds,
            batch_size=10)
        self.api = ThreeMAPI(_db)
        self.metadata_client = SimplifiedOPDSLookup(
            "http://metadata.alpha.librarysimplified.org/")

    def identifier_query(self):
        return self._db.query(Identifier).filter(
            Identifier.type == Identifier.THREEM_ID)

    def process_identifier(self, identifier):
        metadata = self.api.bibliographic_lookup(identifier)
        license_pool = identifier.licensed_through
        for format in metadata.formats:
            print "%s: %s - %s" % (identifier.identifier, format.content_type,
                                   format.drm_scheme)
            mech = license_pool.set_delivery_mechanism(format.content_type,
                                                       format.drm_scheme,
                                                       format.link)
Ejemplo n.º 6
0
 def __init__(self, _db):
     self._db = _db
     self.conf = Configuration.authentication_policy()
     self.overdrive = OverdriveAPI.from_environment(self._db)
     self.threem = ThreeMAPI.from_environment(self._db)
     self.axis = Axis360API.from_environment(self._db)
Ejemplo n.º 7
0
email = os.environ.get("DEFAULT_NOTIFICATION_EMAIL_ADDRESS",
                       "*****@*****.**")

_db = production_session()
patron, ignore = get_one_or_create(_db,
                                   Patron,
                                   authorization_identifier=barcode)

borrow_identifier = Identifier.parse_urn(_db, borrow_urn, True)[0]
hold_identifier = Identifier.parse_urn(_db, hold_urn, True)[0]
borrow_pool = borrow_identifier.licensed_through
hold_pool = hold_identifier.licensed_through

if any(x.type == Identifier.THREEM_ID
       for x in [borrow_identifier, hold_identifier]):
    threem = ThreeMAPI(_db)
else:
    threem = None

if any(x.type == Identifier.OVERDRIVE_ID
       for x in [borrow_identifier, hold_identifier]):
    overdrive = OverdriveAPI(_db)
else:
    overdrive = None

if any(x.type == Identifier.AXIS_360_ID
       for x in [borrow_identifier, hold_identifier]):
    axis = Axis360API(_db)
else:
    axis = None
sys.path.append(os.path.abspath(package_dir))
from core.model import (
    production_session,
    DataSource,
    Work,
    Edition,
)
from overdrive import (OverdriveAPI, OverdriveRepresentationExtractor)
from threem import ThreeMAPI
from core.opds_import import SimplifiedOPDSLookup

lookup = SimplifiedOPDSLookup("http://metadata.alpha.librarysimplified.org/")

_db = production_session()
overdrive = OverdriveAPI(_db)
threem = ThreeMAPI(_db)

q = _db.query(Edition).join(Edition.data_source).filter(
    DataSource.name.in_([DataSource.OVERDRIVE])).filter(Edition.author == '')
print "Fixing %s books." % q.count()
for edition in q:
    if edition.data_source.name == DataSource.OVERDRIVE:
        data = overdrive.metadata_lookup(edition.primary_identifier)
        metadata = OverdriveRepresentationExtractor.book_info_to_metadata(data)
    else:
        metadata = threem.bibliographic_lookup(edition.primary_identifier)
    metadata.update_contributions(_db,
                                  edition,
                                  metadata_client=lookup,
                                  replace_contributions=True)
    if edition.work:
    production_session,
    DataSource,
    Work,
    Edition,
)
from overdrive import (
    OverdriveAPI,
    OverdriveRepresentationExtractor
)
from threem import ThreeMAPI
from core.opds_import import SimplifiedOPDSLookup
lookup = SimplifiedOPDSLookup("http://metadata.alpha.librarysimplified.org/")

_db = production_session()
overdrive = OverdriveAPI(_db)
threem = ThreeMAPI(_db)

q = _db.query(Edition).join(Edition.data_source).filter(DataSource.name.in_([DataSource.OVERDRIVE])).filter(Edition.author=='')
print "Fixing %s books." % q.count()
for edition in q:
    if edition.data_source.name==DataSource.OVERDRIVE:
        data = overdrive.metadata_lookup(edition.primary_identifier)
        metadata = OverdriveRepresentationExtractor.book_info_to_metadata(data)
    else:
        metadata = threem.bibliographic_lookup(edition.primary_identifier)
    metadata.update_contributions(_db, edition, metadata_client=lookup,
                                  replace_contributions=True)
    if edition.work:
        edition.work.calculate_presentation()
    else:
        edition.calculate_presentation()
 def __init__(self, _db, interval_seconds=None):
     super(SetDeliveryMechanismMonitor, self).__init__(
         _db, "20151002 migration - Correct medium of mislabeled audiobooks",
         interval_seconds, batch_size=100)
     self.overdrive = OverdriveAPI(_db)
     self.threem = ThreeMAPI(_db)
Ejemplo n.º 11
0
 def __init__(self, _db, auth=None, overdrive=None, threem=None, axis=None):
     self._db = _db
     self.auth = auth or Authenticator.from_config(self._db)
     self.overdrive = overdrive or OverdriveAPI.from_environment(self._db)
     self.threem = threem or ThreeMAPI.from_environment(self._db)
     self.axis = axis or Axis360API.from_environment(self._db)