diff --git a/eossr/api/__init__.py b/eossr/api/__init__.py index 954b19027456e4df6564f8fb9b3a35e337288133..c45bcba149df257e7084016e3e60dd28e517be8f 100644 --- a/eossr/api/__init__.py +++ b/eossr/api/__init__.py @@ -13,6 +13,7 @@ escape_community = 'escape2020' def get_ossr_records(search='', sandbox=False, **kwargs): """ Search the OSSR for records whose names or descriptions include the provided string `search`. + The default record type is 'software' or 'record'. Function rewritten from pyzenodo3 (https://github.com/space-physics/pyzenodo3) :param search: string @@ -22,12 +23,19 @@ def get_ossr_records(search='', sandbox=False, **kwargs): Common arguments are: - size: int Number of results to return + Default = 100 - all_versions: int Show (1) or hide (0) all versions of records - - type: string + - type: string or list[string] + Default: ['software', 'dataset'] Records of the specified type (Publication, Poster, Presentation, Software, ...) - - keywords: string + A logical OR is applied in case of a list + - keywords: string or list[string] Records with the specified keywords + A logical OR is applied in case of a list + - file_type: string or list[string] + Records from the specified keywords + A logical OR is applied in case of a list :return: list of `Record` @@ -41,7 +49,14 @@ def get_ossr_records(search='', sandbox=False, **kwargs): # if another community is specified, a logical OR is apply be zenodo API, # thus potentially finding entries that are not part of escape2020 # ruling out that possibility at the moment + if 'communities' in kwargs and kwargs['communities'] != escape_community: + raise NotImplementedError("Searching in another community will search outside of the OSSR" + "Use `eossr.api.zenodo.get_zenodo_records` to do so" + ) kwargs['communities'] = escape_community + # OSSR is limited to software and datasets + kwargs.setdefault('type', ['software', 'dataset']) + return get_zenodo_records(search, sandbox=sandbox, **kwargs) diff --git a/eossr/api/tests/test_api.py b/eossr/api/tests/test_api.py index 48d9fcc53ee1c647887b38b08e3a609863f6f680..610f2d7e8d9c3e2455a8c55edf9f34e1b999e2e2 100644 --- a/eossr/api/tests/test_api.py +++ b/eossr/api/tests/test_api.py @@ -3,7 +3,7 @@ from eossr import api def test_get_ossr_records(): ossr_records = api.get_ossr_records() - assert len(ossr_records) >= 15 # number of records September 10, 2021 + assert len(ossr_records) >= 12 # number of records October 01, 2021 all_ids = [rec.data['id'] for rec in ossr_records] assert 4923992 in all_ids # id of the ESCAPE template project diff --git a/eossr/api/zenodo/__init__.py b/eossr/api/zenodo/__init__.py index bcff1320cdd039d96299f679eef6d10bc7384b7e..0758e2748510a376382c315a2f9c93f5ee5a976e 100644 --- a/eossr/api/zenodo/__init__.py +++ b/eossr/api/zenodo/__init__.py @@ -502,12 +502,21 @@ def get_zenodo_records(search='', sandbox=False, **kwargs): Common arguments are: - size: int Number of results to return + Default = 100 - all_versions: int Show (1) or hide (0) all versions of records - - type: string + - type: string or list[string] Records of the specified type (Publication, Poster, Presentation, Software, ...) - - keywords: string + A logical OR is applied in case of a list + - keywords: string or list[string] Records with the specified keywords + A logical OR is applied in case of a list + - communities: string or list[string] + Records from the specified keywords + A logical OR is applied in case of a list + - file_type: string or list[string] + Records from the specified keywords + A logical OR is applied in case of a list :return: list of `Record` @@ -519,8 +528,21 @@ def get_zenodo_records(search='', sandbox=False, **kwargs): **kwargs } + params.setdefault('size', 100) + + def lowercase(param): + if isinstance(param, str): + param = param.lower() + if isinstance(param, list): + param = [char.lower() for char in param] + return param + + for param_name in ['communities', 'type', 'file_type']: + if param_name in kwargs: + params[param_name] = lowercase(kwargs[param_name]) + api_url = zenodo_sandobx_api_url if sandbox else zenodo_api_url - url = api_url + "/records?" + urlencode(params) + url = api_url + "/records?" + urlencode(params, doseq=True) recs = [Record(hit) for hit in requests.get(url).json()["hits"]["hits"]]