comicbox.readinglists ¶
Reading lists: read, combine and write lists of comics in reading order.
Everything codex uses comes from this package. Nothing outside it imports it at module load, and it imports no network library, so a normal comicbox run does not pay for it.
Catalog dataclass ¶
The index of one repository at one ref.
etag revalidates it; fetched is when GitHub last confirmed it.
Source code in comicbox/readinglists/sources/catalog.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
find(path, sha=None) ¶
Find a list by path, else by blob sha, if one is given.
Copies share a sha. Among them, the one with the old path’s file name wins, then the one in its folder; if that leaves more than one, ReadingListFetchError names them rather than guess.
Source code in comicbox/readinglists/sources/catalog.py
131 132 133 134 135 136 137 138 139 140 141 142 | |
search(query) ¶
Find the lists whose path holds every word of query.
Source code in comicbox/readinglists/sources/catalog.py
144 145 146 147 148 149 150 151 152 | |
CatalogEntry dataclass ¶
One list in the catalog.
publisher and category are the first two folders of its path, when it has them. curator is the site the list was taken from, from the file name or a folder, in the model’s spelling.
Source code in comicbox/readinglists/sources/catalog.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
name property ¶
The file name without its .cbl.
CombineResult dataclass ¶
The combined list and what combining found.
provenance is parallel to the list’s entries: the rows each came from, in rank order. only_in is indexed by input: the entries no other input has. name_joins are the entries some row joined on a series name alone, with a start year, volume or cover year: the joins most likely to be wrong. shared_ids are the ids left on more than one entry that no input repeats.
Source code in comicbox/readinglists/combine/__init__.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
Comparison dataclass ¶
How two lists compare.
overlap is the shared issues over all issues. contains is the share of a found in b, then of b found in a. order_agreement is the longest common subsequence of the shared issues over their count, or None when either list is marked unordered, since such a list has no order to agree with.
Source code in comicbox/readinglists/compare.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
Discriminators dataclass ¶
What a row tells its volume by: up to one discriminator of each kind.
year is the year-like one: the start year or, failing that, a volume number of 1900 or more, as a CBL’s Volume="2006" is. volume is a volume number under 1900. Z-Men (1991) volume 2 has both.
Source code in comicbox/readinglists/identity.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
conflicts(other) ¶
Tell whether two rows are of two volumes.
They conflict when they have a discriminator of the same kind and those differ, in either kind: the 2011 and 2016 volumes, or volumes 1 and 2. A start year and volume 2 cannot be compared.
Source code in comicbox/readinglists/identity.py
171 172 173 174 175 176 177 178 179 | |
shares_a_kind(other) ¶
Tell whether two rows have a discriminator of one kind each.
Source code in comicbox/readinglists/identity.py
165 166 167 168 169 | |
EntryOrigin dataclass ¶
A row of an input: input_index ranks the input, row its entry.
Source code in comicbox/readinglists/combine/__init__.py
46 47 48 49 50 51 | |
IdConflict dataclass ¶
Two values for one source on one issue: one of the lists is wrong.
Combined entry entry keeps kept for source, a database; the row at input_index and row, joined to it, had dropped. A barcode that differs is a printing or an edition, so it is never one.
Source code in comicbox/readinglists/combine/__init__.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
MetronListSummary dataclass ¶
One reading list a Metron search found.
curator is the site the list was taken from, lowercased like a fetched list’s source, or None. rating is the average of rating_count ratings, or None when there are none.
Source code in comicbox/readinglists/formats/metron_api.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
OrderConflict dataclass ¶
An input puts combined entry entry somewhere the backbone does not.
Source code in comicbox/readinglists/combine/__init__.py
54 55 56 57 58 59 60 | |
ParsedIssue dataclass ¶
An issue name, normalized, and the number and suffix read out of it.
Source code in comicbox/readinglists/identity.py
61 62 63 64 65 66 67 | |
ReadingListError ¶
Bases: ComicboxError
A reading list could not be read, converted, combined or written.
Source code in comicbox/exceptions.py
140 141 | |
ReadingListFetchError ¶
Bases: ReadingListError
A reading list could not be fetched.
A network failure, an HTTP error, a refused URL, a download over the size cap, or a missing credential. A cancel, or a spent quota, raises OnlineLookupAbortedError instead, as tagging does.
Source code in comicbox/exceptions.py
157 158 159 160 161 162 163 164 | |
ReadingListFormat dataclass ¶
A reading-list file format.
Frozen because it is an enum value. tokens are the names the CLI and the API accept for it, unique across formats. validator_spec names a schema file under comicbox/schemas/, built only when something validates.
Source code in comicbox/readinglists/formats/__init__.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
schema_class property ¶
The transform’s schema class.
ReadingListFormatError ¶
Bases: ReadingListError
A document is not a reading list in any format comicbox reads.
Source code in comicbox/exceptions.py
144 145 | |
ReadingListFormats ¶
Bases: Enum
Reading-list file formats.
Source code in comicbox/readinglists/registry.py
35 36 37 38 39 40 41 | |
ReadingListResult dataclass ¶
A reading list read from a document or fetched from a database.
reading_list is the model’s inner mapping. fmt is the format the document was in, or None for a list built from an online database’s records, such as a Metron reading list. warnings name every key or value the read dropped, changed or guessed, each starting with its path; they are returned, not logged.
Source code in comicbox/readinglists/serialize.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
ReadingListSession ¶
Fetch reading lists from URLs and online sources.
credentials are an OnlineCredentials, as OnlineSession takes; without them the config’s online.auth is used. config is a ComicboxSettings; without it the usual config files and environment are read once. on_event receives the ReadingListFetch* events. client_name names the embedding application in the outgoing User-Agent.
A context manager: leaving it closes the connections the session opened.
Source code in comicbox/readinglists/session.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
cancelled property ¶
The event cancel() sets, for sources that wait.
credentials property ¶
The credentials the session was given, if any.
settings property ¶
The settings every fetch uses.
__enter__() ¶
Use the session in a with block.
Source code in comicbox/readinglists/session.py
87 88 89 | |
__exit__(*_exc_info) ¶
Close the session’s connections.
Source code in comicbox/readinglists/session.py
91 92 93 | |
__init__(*, credentials=None, config=None, on_event=None, client_name=None) ¶
Read the config once; open nothing until the first fetch.
Source code in comicbox/readinglists/session.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
cancel() ¶
Stop the session: the fetch under way, or the next, raises.
Source code in comicbox/readinglists/session.py
105 106 107 | |
catalog(*, refresh=False) ¶
Get the index of the reading-list catalog on GitHub.
The repository and ref are readinglists.catalog_repo and catalog_ref. The index is cached under the online cache directory: within readinglists.catalog_ttl no request is made, and after it the cached index is revalidated. refresh asks GitHub now.
Source code in comicbox/readinglists/session.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
check_cancelled() ¶
Raise if the session was cancelled.
Source code in comicbox/readinglists/session.py
125 126 127 128 129 | |
close() ¶
Close the HTTP client and Metron’s shared sessions, if opened.
Comic Vine’s shared client is left open. Closing it closes its rate-limit buckets, which can fail a tagging lookup in the same process that holds one; OnlineSession.close releases it.
Source code in comicbox/readinglists/session.py
109 110 111 112 113 114 115 116 117 118 119 120 121 | |
emit(event) ¶
Hand an event to the caller’s handler, if any.
Source code in comicbox/readinglists/session.py
136 137 138 139 | |
fetch_catalog(path, *, sha=None) ¶
Fetch a list from the catalog by its path.
Paths change there; when path is gone and sha names the blob it had, the list with that sha is fetched in its place. The result’s source is of kind catalog, keyed by the path it was found at, with the blob sha as its revision.
Source code in comicbox/readinglists/session.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
fetch_comicvine_arc(arc_id) ¶
Fetch a Comic Vine story arc as an unordered list.
Comic Vine names an arc’s issues by id alone, so after the arc come its issues, a hundred a call, then their volumes the same way: an arc of N issues in V volumes costs 1 + ceil(N/100) + ceil(V/100) calls, each on its own hourly budget. Progress events count the issues as they arrive. A budget already spent fails the fetch at once, saying when it frees, rather than waiting.
Comic Vine has no conditional request, so there is no if_modified_since: compare the result’s source revision instead. Needs a Comic Vine API key. The result has no fmt.
Source code in comicbox/readinglists/session.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
fetch_metron_arc(arc_id, *, if_modified_since=None) ¶
Fetch a Metron story arc as an unordered list.
Returns None, having fetched no issues, when the arc is unchanged since if_modified_since. Needs a Metron API token.
Source code in comicbox/readinglists/session.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
fetch_metron_list(list_id, *, if_modified_since=None) ¶
Fetch a Metron reading list, in its order.
Returns None, having fetched no items, when the list is unchanged since if_modified_since. Progress events count the items as their pages arrive. Needs a Metron API token. The result has no fmt: it was read from no document.
Source code in comicbox/readinglists/session.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
fetch_url(url) ¶
Fetch a list from an http or https URL, in any format comicbox reads.
Redirects are followed and the download is capped at readinglists.max_download_bytes. Its source is of kind url. A user name and password in the URL are sent, and never recorded.
Source code in comicbox/readinglists/session.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
fetching(kind, key) ¶
Bracket one fetch with its start and finish events.
Source code in comicbox/readinglists/session.py
154 155 156 157 158 159 160 161 162 | |
http() ¶
Get the session’s HTTP client, built on first use.
Source code in comicbox/readinglists/session.py
141 142 143 144 145 146 147 148 149 150 151 152 | |
load_fetched(data, source) ¶
Read fetched bytes as a list from source, detecting the format.
A document that will not read names where it came from, as a file’s error names its path.
Source code in comicbox/readinglists/session.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
search_catalog(query) ¶
Find the catalog’s lists whose path holds every word of query.
Source code in comicbox/readinglists/session.py
316 317 318 | |
search_metron(*, name=None, curator=None, username=None, modified_since=None) ¶
Search Metron’s reading lists: public ones and the token’s own.
curator is a site Metron credits lists to, such as cbro. Needs a Metron API token.
Source code in comicbox/readinglists/session.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
Refused dataclass ¶
A comic refused for missing entry position (from 0), and why.
Source code in comicbox/readinglists/match.py
111 112 113 114 115 116 117 | |
RefusedReason ¶
Bases: StrEnum
Why a comic that looked like a missing entry was refused.
Source code in comicbox/readinglists/match.py
102 103 104 105 106 107 108 | |
SharedId dataclass ¶
A database id the combined list holds on more than one entry.
No input repeats it, so it names one issue, but the rows that carry it could not all be joined: one input gave the issue twice, with a different id each time, and a row of one input joins at most one row of another. That is bad data worth showing. entries are the positions.
Source code in comicbox/readinglists/combine/__init__.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
SmartListError ¶
Bases: ReadingListFormatError
A ComicRack smart list.
Its <Matchers> are rules that select comics from a library, not a list of issues, so there is nothing to read.
Source code in comicbox/exceptions.py
148 149 150 151 152 153 154 | |
SourceKind ¶
Bases: StrEnum
Where a list came from: the vocabulary of a source’s kind.
A source with a key and no revision is a pointer: the list is known to exist there and was not fetched from it.
Source code in comicbox/readinglists/schema.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
Verdict ¶
Bases: StrEnum
What two lists are to each other, decided in this order.
Source code in comicbox/readinglists/compare.py
48 49 50 51 52 53 54 55 56 57 | |
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 | |
detect_format(data) ¶
Detect a reading list’s format by its content, not its file name.
XML by its root element; JSON and YAML by their top-level keys. JSON is tried before YAML, since every JSON document is also YAML.
Source code in comicbox/readinglists/registry.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
discriminators(entry) ¶
Get what an entry tells its volume by.
Source code in comicbox/readinglists/identity.py
186 187 188 189 190 191 192 193 | |
dumps(reading_list, fmt) ¶
Write a reading list in a format.
The list is validated against the model first, so a hand-built mapping is checked before it is written. lost_fields says what the format cannot carry.
Source code in comicbox/readinglists/serialize.py
277 278 279 280 281 282 283 284 285 286 287 | |
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 | |
entry_keys(entry) ¶
List the keys that identify an entry’s issue, strongest first.
("id", source, key) for each issue id, best ranked source first, then ("name", series, "year", year, number, suffix) by the start year or a year-like volume, then ("name", series, "volume", volume, number, suffix) by a volume number under 1900, then the weakest, ("name-year", series, cover year, number, suffix). Two entries are the same issue when they share a key and their discriminators do not conflict (Discriminators.conflicts): Z-Men (1963) and Z-Men (1991) may both be volume 1. An entry with none, no id and no series and issue with a start year, volume or cover year, matches nothing.
Source code in comicbox/readinglists/identity.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
get_format(fmt) ¶
Resolve a format token such as yaml, or pass a member through.
Source code in comicbox/readinglists/registry.py
62 63 64 65 66 67 68 69 70 | |
load(path, *, fmt=None) ¶
Read a reading list from a file, detecting its format if not given.
Source code in comicbox/readinglists/serialize.py
261 262 263 264 265 266 | |
loads(data, *, fmt=None) ¶
Read a reading list from a string or bytes, detecting its format.
Bytes are UTF-8, except XML, which is read in the encoding it declares.
Source code in comicbox/readinglists/serialize.py
250 251 252 253 254 255 256 257 258 | |
lost_fields(reading_list, fmt) ¶
Name what writing this list in a format and reading it back would change.
Exact: the list is written, read back and compared. Header keys such as sources, entry paths such as entries.date.cover_date, and entries #2, #5 for entries the format cannot write at all.
Source code in comicbox/readinglists/serialize.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
name_variants(entry) ¶
List the series names to try for an entry, normalized, in order.
The name as given; the name without a trailing year or volume in parentheses (Bladehawk (2016), X (Vol. 2)), when it has one; the name without a leading article; and the name without a reprint suffix such as TPB or Omnibus. A year or volume is never added: Ivory Knight is not the series Ivory Knight 2020. For matching a list against comics only: entry_keys stays strict, so combine never joins on a variant.
Source code in comicbox/readinglists/identity.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
normalize_series(name) ¶
Normalize a series name for comparing.
Latin accents are dropped (Pokémon is pokemon), case is folded, a volume suffix is stripped, and every run of characters that are not letters or digits, in any script, becomes one space, so ワンピース keeps a name. Only the Combining Diacritical Marks block is dropped: other combining marks, such as kana voicing (ピ is not ヒ), are part of the letter and recompose with it. An ASCII name normalizes as lowercase letters and digits with single spaces between them.
Source code in comicbox/series_name.py
22 23 24 25 26 27 28 29 30 31 32 33 34 | |
parse_issue(text) ¶
Normalize an issue name and split it into its number and suffix.
The comicbox rules: #004AU is 4AU, number 4 and suffix AU; ½ is .5. 3 and 3.0 have equal numbers. -1 is a real issue number: IssueField.split_issue reads its sign.
Source code in comicbox/readinglists/identity.py
79 80 81 82 83 84 85 86 87 88 89 | |
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 | |