aoptk.literature.utils

Classes

AsyncRequestLimiter

Asynchronous request limiter to control the rate of API calls.

Functions

is_europepmc_id(→ bool)

Check if the given publication ID is a EuropePMC ID.

convert_image_format(→ list[pathlib.Path])

Convert every image in a list to the specified format.

convert_to_png(→ None)

Convert an image to PNG format.

_image_in_this_format_already_exists(→ bool)

Check if the image is already in the target format.

remove_pmc_prefix(→ list[aoptk.literature.id.ID])

Remove the 'PMC' prefix from ID.

Module Contents

class aoptk.literature.utils.AsyncRequestLimiter(requests_per_second: int)[source]

Asynchronous request limiter to control the rate of API calls.

min_interval[source]
_lock[source]
_next_allowed = 0.0[source]
async wait_turn() None[source]

Wait until it’s the turn for the next request based on the rate limit.

aoptk.literature.utils.is_europepmc_id(publication_id: aoptk.literature.id.ID) bool[source]

Check if the given publication ID is a EuropePMC ID.

aoptk.literature.utils.convert_image_format(images_to_convert_path: list[pathlib.Path], target_format: str = 'png') list[pathlib.Path][source]

Convert every image in a list to the specified format.

Parameters:
  • images_to_convert_path – The images to convert.

  • target_format – The desired image format (e.g., ‘png’, ‘jpg’).

aoptk.literature.utils.convert_to_png(inpath: pathlib.Path, outpath: pathlib.Path) None[source]

Convert an image to PNG format.

Parameters:
  • inpath – The path of the input image.

  • outpath – The path where the converted image will be saved.

aoptk.literature.utils._image_in_this_format_already_exists(target_format: str, image_path: pathlib.Path) bool[source]

Check if the image is already in the target format.

Parameters:
  • target_format – The desired image format (e.g., ‘png’, ‘jpg’).

  • image_path – The path of the image to check.

aoptk.literature.utils.remove_pmc_prefix(ids: list[aoptk.literature.id.ID]) list[aoptk.literature.id.ID][source]

Remove the ‘PMC’ prefix from ID.

Parameters:

ids (list[ID]) – A list of IDs to remove the prefix from.