Ejemplo n.º 1
0
def readlink_multiple(bibkey_str, options):
    requests = bibkey_str.split('|')
    # make mapping between maybe-id and key-to-use
    rmap = {}
    for r in requests:
        if r[:3].lower() == 'id:':
            parts = r.split(';')
            if len(parts) != 2:
                return {}
            key = parts[0][3:]
            val = parts[1]
        else:
            key = r
            val = r
        rmap[key] = val
    records = dynlinks.query_docs(rmap.values())
    datas = dynlinks.process_result(records, 'data')
    details = dynlinks.process_result(records, 'details')

    formatted = {}
    for k in records.keys():
        formatted[k] = format_one_request(records[k], datas[k], details[k])

    result = {}
    for k in rmap.keys():
        f = formatted.get(rmap[k], None)
        if f is not None:
            result[k] = f

    return result
Ejemplo n.º 2
0
def readlink_multiple(bibkey_str, options):
    requests = bibkey_str.split('|')
    # make mapping between maybe-id and key-to-use
    rmap = {}
    for r in requests:
        if r[:3].lower() == 'id:':
            parts = r.split(';')
            if len(parts) != 2:
                return {}
            key = parts[0][3:]
            val = parts[1]
        else:
            key = r
            val = r
        rmap[key] = val
    records = dynlinks.query_docs(rmap.values())
    datas = dynlinks.process_result(records, 'data')
    details = dynlinks.process_result(records, 'details')

    formatted = {}
    for k in records.keys():
        formatted[k] = format_one_request(records[k], datas[k], details[k])

    result = {}
    for k in rmap.keys():
        f = formatted.get(rmap[k], None)
        if f is not None:
            result[k] = f
    
    return result
Ejemplo n.º 3
0
def readlink_single(bibkey, options):
    bka = [bibkey]
    r = dynlinks.query_docs(bka)
    (data, details) = [dynlinks.process_result(r, cmd)[bibkey]
                       for cmd in ('data', 'details')]
    if len(r) == 0:
        return []
    record = r[bibkey]
    return format_one_request(record, data, details)
Ejemplo n.º 4
0
def readlink_single(bibkey, options):
    bka = [bibkey]
    r = dynlinks.query_docs(bka)
    (data, details) = [
        dynlinks.process_result(r, cmd)[bibkey] for cmd in ('data', 'details')
    ]
    if len(r) == 0:
        return []
    record = r[bibkey]
    return format_one_request(record, data, details)
Ejemplo n.º 5
0
    def process(self, req):
        requests = req.split('|')
        bib_keys = sum([r.split(';') for r in requests], [])

        # filter out 'id:foo' before passing to dynlinks
        bib_keys = [k for k in bib_keys if k[:3].lower() != 'id:']

        self.docs = dynlinks.query_docs(bib_keys)
        if not self.options.get('no_details'):
            self.detailss = dynlinks.process_result_for_details(self.docs)
        else:
            self.detailss = {}
        dp = dynlinks.DataProcessor()
        self.datas = dp.process(self.docs)
        self.works = dp.works

        # XXX control costs below with [:iaid_limit] - note that this may result
        # in no 'exact' item match, even if one exists
        # Note that it's available thru above works/docs
        iaid_limit = 500
        self.wkey_to_iaids = dict((wkey, get_work_iaids(wkey)[:iaid_limit])
                                  for wkey in self.works)
        iaids = sum(self.wkey_to_iaids.values(), [])
        self.iaid_to_meta = dict((iaid, ia.get_meta_xml(iaid)) for iaid in iaids)

        def lookup_iaids(iaids):
            step = 10
            if len(iaids) > step and not self.options.get('debug_things'):
                result = []
                while iaids:
                    result += lookup_iaids(iaids[:step])
                    iaids = iaids[step:]
                return result
            query = {
                'type': '/type/edition',
                'ocaid': iaids,
            }
            result = web.ctx.site.things(query)
            return result

        ekeys = lookup_iaids(iaids)

        # If returned order were reliable, I could skip the below.
        eds = dynlinks.ol_get_many_as_dict(ekeys)
        self.iaid_to_ed = dict((ed['ocaid'], ed) for ed in eds.values())
        # self.iaid_to_ekey = dict((iaid, ed['key'])
        #                            for iaid, ed in self.iaid_to_ed.items())

        # Work towards building a dict of iaid loanability,
        # def has_lending_collection(meta):
        #     collections = meta.get("collection", [])
        #     return 'lendinglibrary' in collections or 'inlibrary' in collections
        # in case site.store supports get_many (unclear)
        # maybe_loanable_iaids = [iaid for iaid in iaids
        #                         if has_lending_collection(self.iaid_to_meta.get(iaid, {}))]
        # loanable_ekeys = [self.iaid_to_ekey.get(iaid) for iaid in maybe_loanable_iaids]
        # loanstatus =  web.ctx.site.store.get('ebooks' + ekey, {'borrowed': 'false'})

        result = {}
        for r in requests:
            bib_keys = r.split(';')
            if r.lower().startswith('id:'):
                result_key = bib_keys.pop(0)[3:]
            else:
                result_key = r
            sub_result = self.make_record(bib_keys)
            if sub_result:
                result[result_key] = sub_result

        if self.options.get('debug_items'):
            result['ekeys'] = ekeys
            result['eds'] = eds
            result['iaids'] = iaids

        return result