mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-11-13 23:55:40 +00:00
bookmeta, bibfetch, bindings: what a caller needs to trust a cover
bookmeta: Cover::guessed says the file left the choice open — a Kindle book's first image record, or an EPUB image picked because its name says cover — so a caller with a register to ask can prefer that. A cover the file names is never a guess. Cover::extension matches bibfetch's. bibfetch: Open Library answers 403 to more than a hundred covers by ISBN in five minutes from one address. That is now Error::Limited, not Unreachable: the other form of the ISBN is not asked, the cover id still is, since those are not limited, and the CLI exits 75. Covers asked by ISBN are kept three seconds apart across the process (Covers::pace), which stays under the limit however long a run goes. A deadline too long to add to the clock no longer panics; it is no deadline. bindings: fetch_cover and search_title for Python, and catena.Limited, which fetch_identifier raises too when a register refuses for being asked too often. corpus-core: exit 75, a service refused for now.
This commit is contained in:
14 files changed
+334
-16
No files matched your search
@@ -21,6 +21,8 @@ from ._catena import (
|
||||
compose_subjects,
|
||||
count_tokens,
|
||||
cue_windows,
|
||||
Limited,
|
||||
fetch_cover,
|
||||
fetch_identifier,
|
||||
find_citations,
|
||||
fuse_hits,
|
||||
@@ -41,6 +43,7 @@ from ._catena import (
|
||||
record_severity,
|
||||
same_work,
|
||||
scrub,
|
||||
search_title,
|
||||
segment_cues,
|
||||
series_of,
|
||||
shelve,
|
||||
@@ -53,6 +56,7 @@ from ._catena import (
|
||||
|
||||
__all__ = [
|
||||
"__version__",
|
||||
"Limited",
|
||||
"canonical_subject",
|
||||
"chunk_markdown",
|
||||
"citation_prompt",
|
||||
@@ -62,6 +66,7 @@ __all__ = [
|
||||
"compose_subjects",
|
||||
"count_tokens",
|
||||
"cue_windows",
|
||||
"fetch_cover",
|
||||
"fetch_identifier",
|
||||
"find_citations",
|
||||
"fuse_hits",
|
||||
@@ -82,6 +87,7 @@ __all__ = [
|
||||
"record_severity",
|
||||
"same_work",
|
||||
"scrub",
|
||||
"search_title",
|
||||
"segment_cues",
|
||||
"series_of",
|
||||
"shelve",
|
||||
|
||||
@@ -103,6 +103,40 @@ def fetch_identifier(
|
||||
"""
|
||||
...
|
||||
|
||||
class Limited(Exception):
|
||||
"""A register refused because it has been asked too often; ask again later."""
|
||||
|
||||
def fetch_cover(
|
||||
isbn: str,
|
||||
cover_id: int | None = ...,
|
||||
size: str = ...,
|
||||
polite: str | None = ...,
|
||||
timeout: int = ...,
|
||||
deadline: int = ...,
|
||||
) -> dict[str, Any] | None:
|
||||
"""The cover Open Library has for a book, by ISBN, then by cover id.
|
||||
|
||||
A dict with `bytes`, `media_type`, `extension`, `source` and `url`, or
|
||||
`None` when there is none. Raises `Limited` when Open Library refused for
|
||||
being asked too often. Blocks on the network.
|
||||
"""
|
||||
...
|
||||
|
||||
def search_title(
|
||||
title: str,
|
||||
author: str | None = ...,
|
||||
limit: int = ...,
|
||||
polite: str | None = ...,
|
||||
timeout: int = ...,
|
||||
attempts: int = ...,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""The editions the registers list for a title and author, in their order.
|
||||
|
||||
Records shaped like `fetch_identifier`'s. Use `same_work` to decide which
|
||||
one is the book. Blocks on the network.
|
||||
"""
|
||||
...
|
||||
|
||||
def colophon_prompt(
|
||||
record: dict[str, Any], text: str, pages: int = ...
|
||||
) -> str | None:
|
||||
|
||||
Reference in new issue
Block a user