oapen_books.bulk_import

Attributes

OAPEN_REST_URL

DEFAULT_LIMIT

logger

plugin

here

Functions

fetch_books(...)

Fetch open-access books from the OAPEN Library REST API.

bulk_translate(...)

Translate a list of raw OAPEN item dicts to OME EducationResource cards.

bulk_import(→ list[dict])

Fetch OAPEN books by search query and cache results locally.

Module Contents

oapen_books.bulk_import.OAPEN_REST_URL = 'https://library.oapen.org/rest/search'
oapen_books.bulk_import.DEFAULT_LIMIT = 50
oapen_books.bulk_import.logger
oapen_books.bulk_import.plugin
async oapen_books.bulk_import.fetch_books(query: str, limit: int = DEFAULT_LIMIT, offset: int = 0) list[server.plugins.oapen_books.oapen_models.OapenItem]

Fetch open-access books from the OAPEN Library REST API.

Args:

query: Search query string (e.g. "python programming"). limit: Maximum number of results to return (default 50). offset: Pagination offset (default 0).

Returns:

A list of OapenItem records.

Raises:

RuntimeError: If the API request fails.

oapen_books.bulk_import.bulk_translate(items: list[dict]) collections.abc.Iterator[server.plugins.ome_plugin.EducationResource]

Translate a list of raw OAPEN item dicts to OME EducationResource cards.

oapen_books.bulk_import.bulk_import(query: str = 'python programming', limit: int = DEFAULT_LIMIT, cache_path: pathlib.Path | None = None) list[dict]

Fetch OAPEN books by search query and cache results locally.

On the first run the function calls the OAPEN REST API and writes the results to cache_path. Subsequent calls read from the cache so that the network is not hit again.

Args:

query: Search query passed to the OAPEN REST API. limit: Maximum number of results to fetch from the API. cache_path: Path for the local JSON cache. Defaults to

oapen_python_books.json next to this file.

Returns:

A list of serialised EducationResource dicts.

oapen_books.bulk_import.here