def listrecords(endpoint='http://dspace.mit.edu/oai/request', oaiset=None, limit=100): """ e.g.: curl "http://localhost:8880/oai.listrecords.json?oaiset=hdl_1721.1_18193&limit=10" """ limit = int(limit) if not oaiset: raise ValueError('OAI set required') remote = oaiservice(endpoint, logger) records = remote.list_records(oaiset)[:limit] exhibit_records = [] for rid, rinfo in records: erecord = {u'id': rid} for k, v in rinfo.iteritems(): if len(v) == 1: erecord[k] = v[0] else: erecord[k] = v if u'title' in erecord: erecord[u'label'] = erecord[u'title'] exhibit_records.append(erecord) #FIXME: This profile is NOT correct. Dumb copy from CDM endpoint. Please fix up below return json.dumps({'items': exhibit_records, 'data_profile': PROFILE}, indent=4)
def listrecords(endpoint='http://dspace.mit.edu/oai/request', oaiset=None, limit=5000): """ e.g.: curl "http://localhost:8880/oai.listrecords.json?oaiset=hdl_1721.1_18193&limit=10" """ limit = int(limit) if not oaiset: raise ValueError('OAI set required') remote = oaiservice(endpoint, logger) records = remote.list_records(oaiset)[:limit] exhibit_records = [] properties_used = set() # track the properties in use for rid, rinfo in records: erecord = {u'id': rid} for k, v in rinfo.iteritems(): if len(v) == 1: erecord[k] = v[0] else: erecord[k] = v if u'title' in erecord: erecord[u'label'] = erecord[u'title'] properties_used.update(erecord.keys()) exhibit_records.append(erecord) PROFILE["properties"][:] = strip_unused_profile_properties(PROFILE["properties"],properties_used) #FIXME: This profile is NOT correct. Dumb copy from CDM endpoint. Please fix up below return json.dumps({'items': exhibit_records, 'data_profile': PROFILE}, indent=4)
def listsets(endpoint='http://dspace.mit.edu/oai/request', limit=100): """ e.g.: curl "http://localhost:8880/oai.listsets.json?limit=10" """ limit = int(limit) remote = oaiservice(endpoint, logger) sets = remote.list_sets()[:limit] return json.dumps(sets, indent=4)
def listsets(endpoint='http://dspace.mit.edu/oai/request', limit=5000): """ e.g.: curl "http://localhost:8880/oai.listsets.json?limit=10" """ limit = int(limit) remote = oaiservice(endpoint, logger) sets = remote.list_sets()[:limit] return json.dumps(sets, indent=4)