internetarchive / internetarchive/openlibrary-client
Update Author Search to use official Author endpoint?
- Dominant language
- Python
- Stars
- 506
- Forks
- 110
- PR merge metrics
- No merged PRs in 30d
Description
```
@classmethod
def search(cls, name=None, birth_date=None, death_date=None, limit=5):
"""
Searches for an Open Library author by
Args:
name (str) - The first, last, nickname, or full name of the author
birth_date (str) - The birth date of the Author exactly as it appears in OL (e.g. "January 5, 2013").
Must be in quotes if the date is mult-terms, e.g. "\"January 5\""
You can also do something like "*1982*" without quotes to do
partial matching, e.g. on year.
date_date (str) - The death date of the Author; same conditions as birth_date
limit (int) - How many results to limit by
Usage:
>>> ol.common.Author.search(name='tolkien', birth_date="*1892*", death_date="*1973*")
[u'OL26320A]'
Returns:
The first matching OL Author ID/key from the API results, if there is one, else None
"""
params = {'name': name, 'birth_date': birth_date, 'death_date': death_date}
paramstr = '+'.join(['%s:%s' % (k, v) for (k, v) in params.items() if v])
url = cls.OL.base_url + '/search/authors.json?limit=%s&q=%s' % (limit, paramstr)
r = requests.get(url)
try:
authors = r.json().get('docs', [])
except requests.JSONDecodeError as e:
return []
return [a['key'] for a in authors]
```
@hornc, @cdrini thoughts? Not sure if the existing autocomplete code allows faceting by birth/death date
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.