Skip to content
Snippets Groups Projects
Commit b94653ce authored by vuillaut's avatar vuillaut
Browse files

building upon pyzenodo3 to search the OSSR and get records

parent 5f18cfdd
No related branches found
No related tags found
1 merge request!15api
from pyzenodo3 import Record, Zenodo
import requests
__all__ = [
'Ossr',
'pprint_record',
'get_all_ossr_records'
]
escape_community = 'escape2020'
class Ossr(Zenodo):
def __init__(self):
super().__init__()
def search(self, search: str, **kwargs) -> list[Record]:
"""
Search the ESCAPE OSSR
:param search: string
:param kwargs: Zenodo query arguments.
For an exhaustive list, see the query arguments at https://developers.zenodo.org/#list36
Common arguments are:
- size: int
Number of results to return
- all_versions: int
Show (1) or hide (0) all versions of records
- type: string
Records of the specified type (Publication, Poster, Presentation, Software, ...)
- keywords: string
Records with the specified keywords
:return:
list of `pyzenodo3.Record`
"""
search = search.replace("/", " ") # zenodo can't handle '/' in search query
# if another community is specified, a logical OR is apply be zenodo API,
# thus potentially finding entries that are not part of escap2020
# ruling out that possibility at the moment
kwargs['communities'] = escape_community
params = {
'q': search,
**kwargs
}
recs = self._get_records(params)
if not recs:
raise LookupError(f"No records found for search {search}")
return recs
def pprint_record(record: Record):
"""
Pretty print of a record
:param record: `pyzenodo3.Record`
"""
entry_id = record.data['id']
metadata = record.data['metadata']
print(f"=== Record #{entry_id} : {metadata['title']} ===")
print(metadata['description'])
print('\n')
def get_all_ossr_records():
"""
Retrieve all OSSR entries.
Potentially long when the number of entries in the OSSR increases.
:return: list[pyzenodo3.Record]
"""
ossr = Ossr()
r = requests.get(ossr.base_url+'/records', params={'communities': escape_community})
number_of_ossr_entries = r.json()['aggregations']['access_right']['buckets'][0]['doc_count']
return ossr.search('', size=number_of_ossr_entries)
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