Metron reading lists and story arcs, through the shared paced session.
The calls go through MetronOnlineSource.session(), so they queue at the same rate gate and fill the same response cache as tagging with the same token. Imported only when a Metron fetch runs: it loads mokkari.
check_token(session)
Raise unless a Metron API token is set, before a fetch begins.
Source code in comicbox/readinglists/sources/metron.py
| def check_token(session: FetchContext) -> None:
"""Raise unless a Metron API token is set, before a fetch begins."""
_configured(session)
|
fetch_arc(session, arc_id, *, if_modified_since=None)
Fetch a story arc as a list, or None when it is unchanged since then.
Source code in comicbox/readinglists/sources/metron.py
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247 | def fetch_arc(
session: FetchContext,
arc_id: int,
*,
if_modified_since: datetime | None = None,
) -> ReadingListResult | None:
"""Fetch a story arc as a list, or None when it is unchanged since then."""
kind, key = SourceKind.METRON_ARC.value, str(arc_id)
counter = _PageCounter(session, kind, key, _ARC_ISSUES_PAGE)
with _calling(session, f"Metron arc {arc_id}", counter) as source:
api = source.session()
arc = api.arc(arc_id, if_modified_since=if_modified_since)
if arc is None:
return None
if if_modified_since is None:
issues = api.arc_issues_list(arc_id)
else:
with source.refreshing_session() as fresh:
arc = fresh.arc(arc_id) or arc
issues = fresh.arc_issues_list(arc_id)
return reading_list_from_metron_arc(arc, issues)
|
fetch_list(session, list_id, *, if_modified_since=None)
Fetch a reading list, or None when it is unchanged since then.
Source code in comicbox/readinglists/sources/metron.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224 | def fetch_list(
session: FetchContext,
list_id: int,
*,
if_modified_since: datetime | None = None,
) -> ReadingListResult | None:
"""Fetch a reading list, or None when it is unchanged since then."""
kind, key = SourceKind.METRON_LIST.value, str(list_id)
counter = _PageCounter(session, kind, key, _ITEMS_PAGE)
with _calling(session, f"Metron reading list {list_id}", counter) as source:
api = source.session()
header = api.reading_list(list_id, if_modified_since=if_modified_since)
if header is None:
return None
if if_modified_since is None:
items = api.reading_list_items(list_id)
else:
# Changed since then, so the cached header and items are older
# still: fetch both anew, and leave the cache holding them.
with source.refreshing_session() as fresh:
header = fresh.reading_list(list_id) or header
items = fresh.reading_list_items(list_id)
return reading_list_from_metron(header, items)
|
search(session, *, name=None, curator=None, username=None, modified_since=None)
Search the reading lists the token can see.
Source code in comicbox/readinglists/sources/metron.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 | def search(
session: FetchContext,
*,
name: str | None = None,
curator: str | None = None,
username: str | None = None,
modified_since: datetime | None = None,
) -> list[MetronListSummary]:
"""Search the reading lists the token can see."""
params: dict[str, str | int] = {}
if name:
params["name"] = name
if curator:
params["attribution_source"] = curator.upper()
if username:
params["username"] = username
if modified_since is not None:
params["modified_gt"] = modified_since.isoformat()
with _calling(session, "Metron reading-list search") as source:
rows = source.session().reading_lists_list(params)
return [summary_from_metron(row) for row in rows]
|