def fetch_collection(api: AlephAPI, prefix: Optional[str], foreign_id: str, overwrite: bool = False): path = _fix_path(prefix) collection = api.get_collection_by_foreign_id(foreign_id) if collection is None: return filters = [("collection_id", collection.get("id"))] params = {"empty:properties.parent": "true"} results = api.search("", filters=filters, schemata="Document", params=params) label = collection.get("label") log.info("Dataset [%s]: %s (%d children)", path, label, len(results)) for entity in results: fetch_object(api, path, entity, overwrite=overwrite)
def load_aleph(foreign_id, api_url, api_key): api = AlephAPI(api_url, api_key) collection_id = None if foreign_id is not None: collection = api.get_collection_by_foreign_id(foreign_id) if collection is None: raise click.BadParameter("Cannot find collection: %s" % foreign_id) collection_id = collection.get('id') stdout = click.get_text_stream('stdout') entities = api.stream_entities(collection_id=collection_id, include=['schema', 'properties']) for data in entities: if 'properties' not in data: continue entity = model.get_proxy(data) api_url = urljoin(api.base_url, 'entities/%s' % entity.id) entity.add('alephUrl', api_url, quiet=True) write_object(stdout, entity)