Skip to content
Snippets Groups Projects
Commit d8256d57 authored by Vuillaume's avatar Vuillaume Committed by Enrique Garcia
Browse files

handle lists and lowercase of args in search zenodo / ossr records

parent 0a2863bf
No related branches found
No related tags found
1 merge request!59handle lists and lowercase of args in search zenodo / ossr records
......@@ -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)
......@@ -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
......@@ -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"]]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment