Update Author Search to use official Author endpoint?

Open
#91 2 comments 0 reactions 1 assignee View on GitHub

@mekarpeles is already working on this.

Since Jun 9, 2018.

  • #92 by @mekarpeles — closed without merging

Assessment

This issue has not been assessed yet.

Description

enhancement question
@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

Dominant language
Python
Stars
509
Forks
116
Avg merge
11d 8h
Merged PRs (30d)
4

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from internetarchive/openlibrary-client

All issues in internetarchive/openlibrary-client

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.