Skip to content

comicbox.readinglists.arcs ¶

Arc tags and reading lists.

A comic’s arcs tag, {name: {number}}, is a per-comic view of list membership. These functions go both ways: the entry that refers to a comic, the lists a set of comics’ arc tags describe, and the patch that tags one comic as part of a list.

arc_patch(list_name, number=None) ¶

Build the patch that tags one comic as part of a list.

For write_metadata with merge_mode="additive", so the patch adds the arc and keeps the comic’s others; under update it would replace them.

Source code in comicbox/readinglists/arcs.py
192
193
194
195
196
197
198
199
200
201
def arc_patch(list_name: str, number: int | None = None) -> dict[str, Any]:
    """
    Build the patch that tags one comic as part of a list.

    For ``write_metadata`` with ``merge_mode="additive"``, so the patch adds
    the arc and keeps the comic's others; under ``update`` it would replace
    them.
    """
    arc = {} if number is None else {NUMBER_KEY: number}
    return {ARCS_KEY: {list_name: arc}}

entry_from_comic(metadata) ¶

Build the entry that refers to a comic.

Takes {"comicbox": {...}} or the inner mapping, which is what a ReadResult’s tags holds. Keeps the series name, start year and ids, the volume number, the issue, the cover date and year, and the issue-level ids.

Source code in comicbox/readinglists/arcs.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def entry_from_comic(metadata: Mapping[str, Any]) -> dict[str, Any]:
    """
    Build the entry that refers to a comic.

    Takes ``{"comicbox": {...}}`` or the inner mapping, which is what a
    ``ReadResult``'s ``tags`` holds. Keeps the series name, start year and
    ids, the volume number, the issue, the cover date and year, and the
    issue-level ids.
    """
    comic = _comic(metadata)
    entry: dict[str, Any] = {}
    if series := _pick(comic.get(SERIES_KEY), _SERIES_KEYS):
        entry[SERIES_KEY] = series
    if volume := _pick(comic.get(VOLUME_KEY), (NUMBER_KEY,)):
        entry[VOLUME_KEY] = volume
    if issue := _pick(comic.get(ISSUE_KEY), _ISSUE_KEYS):
        entry[ISSUE_KEY] = issue
    if entry_date := _pick(comic.get(DATE_KEY), _DATE_KEYS):
        entry[DATE_KEY] = entry_date
    if identifiers := comic.get(IDENTIFIERS_KEY):
        entry[IDENTIFIERS_KEY] = _plain(identifiers)
    return entry

reading_lists_from_comics(comics) ¶

Build one list per arc that a set of comics is tagged with.

Arc names group case-insensitively and keep the first spelling seen. Copies of one issue are one entry. Entries go by arc number, then cover date, series and issue. Lists come back sorted by name.

Source code in comicbox/readinglists/arcs.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def reading_lists_from_comics(
    comics: Iterable[Mapping[str, Any]],
) -> list[dict[str, Any]]:
    """
    Build one list per arc that a set of comics is tagged with.

    Arc names group case-insensitively and keep the first spelling seen.
    Copies of one issue are one entry. Entries go by arc number, then cover
    date, series and issue. Lists come back sorted by name.
    """
    arcs: dict[str, _ArcMembers] = {}
    for metadata in comics:
        comic = _comic(metadata)
        if not (comic_arcs := comic.get(ARCS_KEY)):
            continue
        entry = entry_from_comic(comic)
        for name, arc in comic_arcs.items():
            members = arcs.setdefault(name.casefold(), _ArcMembers(name))
            members.add(entry, arc or {})
    return [arcs[folded].reading_list() for folded in sorted(arcs)]