pressbooks.bulk_import¶
Attributes¶
Functions¶
|
Validate raw API items into PressbooksBook records. |
|
Fetch and parse a single page of books from the Pressbooks Directory API. |
|
Fetch all matching books from the Pressbooks Directory. |
|
Translate a list of raw Pressbooks book dicts to OME EducationResource cards. |
|
Fetch Pressbooks books by search query and cache results locally. |
|
Fetch Pressbooks books by institution filter and cache results locally. |
Module Contents¶
- pressbooks.bulk_import.PRESSBOOKS_DIRECTORY_URL = 'https://pressbooks.directory'¶
- pressbooks.bulk_import.BOOKS_API_URL = 'https://pressbooks.directory/wp-json/pressbooks/v2/books'¶
- pressbooks.bulk_import.DEFAULT_PER_PAGE = 100¶
- pressbooks.bulk_import.logger¶
- pressbooks.bulk_import.plugin¶
- pressbooks.bulk_import._parse_page(items: list) list[server.plugins.pressbooks.pressbooks_models.PressbooksBook]¶
Validate raw API items into PressbooksBook records.
Uses a Python 3.13+ ExceptionGroup to gather and report all validation errors at once rather than stopping at the first malformed record. Valid records are returned even when some items fail validation.
- async pressbooks.bulk_import._fetch_page(client: httpx.AsyncClient, params: dict[str, str | int]) list[server.plugins.pressbooks.pressbooks_models.PressbooksBook]¶
Fetch and parse a single page of books from the Pressbooks Directory API.
- async pressbooks.bulk_import.fetch_all_books(*, search: str = '', institution: str = '', per_page: int = DEFAULT_PER_PAGE) list[server.plugins.pressbooks.pressbooks_models.PressbooksBook]¶
Fetch all matching books from the Pressbooks Directory.
Fetches the first page to discover the total page count from the
X-WP-TotalPagesresponse header, then gathers all remaining pages concurrently usingasyncio.gather().- Args:
search: Full-text search query (maps to the
?q=UI parameter). institution: Institution name filter (maps to the?inst=UI parameter).Multiple institutions can be joined with
&&(e.g."University at Buffalo&&University of Rochester").per_page: Number of results per page (max 100).
- Returns:
A flat list of all
PressbooksBookrecords.
- pressbooks.bulk_import.bulk_translate(books: list[dict]) collections.abc.Iterator[server.plugins.ome_plugin.EducationResource]¶
Translate a list of raw Pressbooks book dicts to OME EducationResource cards.
- pressbooks.bulk_import.bulk_import_search(search: str, cache_path: pathlib.Path) list[dict]¶
Fetch Pressbooks books by search query and cache results locally.
- Args:
search: Search term to pass to the API. cache_path: Path to the local JSON cache file.
- Returns:
A list of serialised EducationResource dicts.
- pressbooks.bulk_import.bulk_import_institution(institution: str, cache_path: pathlib.Path) list[dict]¶
Fetch Pressbooks books by institution filter and cache results locally.
- Args:
institution: Institution name(s) joined with
&&. cache_path: Path to the local JSON cache file.- Returns:
A list of serialised EducationResource dicts.
- pressbooks.bulk_import.here¶