oercommons.bulk_import

Bulk-import metadata from OER Commons.

Uses the OER Commons search API to fetch Open Educational Resources and translate them into standardised OME EducationResource cards. Results are cached locally to avoid repeated API calls.

Attributes

OERCOMMONS_SEARCH_URL

DEFAULT_SEARCH_QUERY

DEFAULT_BATCH_SIZE

logger

_plugin

here

Functions

fetch_materials(→ list[dict])

Search OER Commons and return raw search-hit dicts.

bulk_translate(...)

Translate raw OER Commons search-hit dicts to OME EducationResource cards.

bulk_import(→ list[dict])

Fetch OER Commons materials and return serialised OME records.

Module Contents

oercommons.bulk_import.OERCOMMONS_SEARCH_URL = 'https://oercommons.org/api/v1/materials/search'
oercommons.bulk_import.DEFAULT_SEARCH_QUERY = 'python'
oercommons.bulk_import.DEFAULT_BATCH_SIZE = 20
oercommons.bulk_import.logger
oercommons.bulk_import._plugin
oercommons.bulk_import.fetch_materials(query: str = DEFAULT_SEARCH_QUERY, batch_size: int = DEFAULT_BATCH_SIZE) list[dict]

Search OER Commons and return raw search-hit dicts.

Each returned dict has the same shape as Model (i.e. it contains _index, _type, _id, _score, _source) so that it can be passed directly to OERCommonsPlugin.make_metadata_card_from_json().

Args:

query: Search query string. batch_size: Maximum number of results to return.

Returns:

A list of raw search-hit dicts.

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

Translate raw OER Commons search-hit dicts to OME EducationResource cards.

Each dict should have the same shape as Model (_index, _type, _id, _score, _source), matching the format returned by the search API and cached by bulk_import().

oercommons.bulk_import.bulk_import(query: str = DEFAULT_SEARCH_QUERY, batch_size: int = DEFAULT_BATCH_SIZE, cache_path: pathlib.Path | None = None) list[dict]

Fetch OER Commons materials and return serialised OME records.

Results are cached locally so that repeated runs do not re-fetch the API.

Args:

query: Search query string (default: "python"). batch_size: Maximum number of results to return (default: 20). cache_path: Path to the local JSON cache file. If None, defaults

to oercommons_python_materials.json next to this module.

Returns:

A list of serialised EducationResource dicts.

oercommons.bulk_import.here