thoth.bulk_import¶
Attributes¶
Functions¶
|
Fetch open-access books from the Thoth GraphQL API. |
|
Translate a list of raw Thoth book dicts to OME EducationResource cards. |
|
Fetch Thoth books by search query and cache results locally. |
Module Contents¶
- thoth.bulk_import.DEFAULT_LIMIT = 50¶
- thoth.bulk_import.THOTH_ENDPOINT = 'https://api.thoth.pub'¶
- thoth.bulk_import.logger¶
- thoth.bulk_import.plugin¶
- thoth.bulk_import.fetch_books(query: str = 'Python', limit: int = DEFAULT_LIMIT, offset: int = 0) list[server.plugins.thoth.thoth_models.ThothBook]¶
Fetch open-access books from the Thoth GraphQL API.
Uses
thothlibrary.ThothClientto query thebooksendpoint with the given search term. The Munch objects returned by the client are converted toThothBookPydantic models for type-safe downstream processing.- Args:
query: Search term passed to the Thoth
booksendpoint filter. limit: Maximum number of results to return (default 50). offset: Pagination offset (default 0).- Returns:
A list of
ThothBookrecords.- Raises:
RuntimeError: If the Thoth API request fails.
- thoth.bulk_import.bulk_translate(items: list[dict]) collections.abc.Iterator[server.plugins.ome_plugin.EducationResource]¶
Translate a list of raw Thoth book dicts to OME EducationResource cards.
- thoth.bulk_import.bulk_import(query: str = 'Python', limit: int = DEFAULT_LIMIT, cache_path: pathlib.Path | None = None) list[dict]¶
Fetch Thoth books by search query and cache results locally.
On the first run the function calls the Thoth GraphQL API and writes the raw book records to cache_path. Subsequent calls read from the cache so that the network is not hit again.
- Args:
query: Search term passed to the Thoth
booksendpoint. limit: Maximum number of results to fetch from the API. cache_path: Path for the local JSON cache. Defaults tothoth_python_books.jsonnext to this file.- Returns:
A list of serialised
EducationResourcedicts.
- thoth.bulk_import.here¶