Reading lists built from Metron’s reading lists and story arcs.
Builders from mokkari objects, read by attribute, so this module imports no network library. Metron is a source, not a format: nothing is written back.
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 | @dataclass(frozen=True, slots=True)
class MetronListSummary:
"""
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.
"""
id: int
name: str
list_type: str
private: bool
curator: str | None
username: str
rating: float | None
rating_count: int
modified: datetime
|
Build a list from a Metron reading list and its items.
Items run in their order, those without one last, each group in the order the API sent them.
Source code in comicbox/readinglists/formats/metron_api.py
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 | def reading_list_from_metron(
header: ReadingListRead, items: Iterable[ReadingListItem]
) -> ReadingListResult:
"""
Build a list from a Metron reading list and its items.
Items run in their ``order``, those without one last, each group in the
order the API sent them.
"""
source = {
SOURCE_KIND_KEY: SourceKind.METRON_LIST.value,
SOURCE_KEY_KEY: str(header.id),
SOURCE_URL_KEY: header.resource_url,
SOURCE_REVISION_KEY: header.modified.isoformat(),
SOURCE_CURATOR_KEY: header.attribution_source.lower(),
SOURCE_CURATOR_URL_KEY: header.attribution_url and str(header.attribution_url),
}
ranked = sorted(
enumerate(items),
key=lambda pair: (pair[1].order is None, pair[1].order or 0, pair[0]),
)
return _load(
{
NAME_KEY: header.name,
DESCRIPTION_KEY: strip_html(header.desc),
LIST_TYPE_KEY: header.list_type,
ORDERED_KEY: True,
# Only a private list says so: a public one has nothing to lose.
PRIVATE_KEY: header.is_private or None,
SOURCES_KEY: [_without_empty(source)],
PREVIOUS_KEY: _list_reference(header.previous),
NEXT_KEY: _list_reference(header.next),
ENTRIES_KEY: [_item_entry(item) for _, item in ranked],
}
)
|
Build an unordered story list from a Metron arc and its issues.
The arc’s issue list carries Metron ids only (F8). An arc that names its Comic Vine arc also gets a pointer source to it.
Source code in comicbox/readinglists/formats/metron_api.py
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 | def reading_list_from_metron_arc(
arc: Arc, issues: Iterable[BaseIssue]
) -> ReadingListResult:
"""
Build an unordered story list from a Metron arc and its issues.
The arc's issue list carries Metron ids only (F8). An arc that names its
Comic Vine arc also gets a pointer source to it.
"""
sources = [
{
SOURCE_KIND_KEY: SourceKind.METRON_ARC.value,
SOURCE_KEY_KEY: str(arc.id),
SOURCE_URL_KEY: str(arc.resource_url),
SOURCE_REVISION_KEY: arc.modified.isoformat(),
}
]
if arc.cv_id:
sources.append(
{
SOURCE_KIND_KEY: SourceKind.COMICVINE_ARC.value,
SOURCE_KEY_KEY: str(arc.cv_id),
}
)
entries = [
_entry(issue, {_METRON: build_identifier(_METRON, "issue", issue.id)})
for issue in issues
]
return _load(
{
NAME_KEY: arc.name,
DESCRIPTION_KEY: strip_html(arc.desc),
LIST_TYPE_KEY: STORY_LIST_TYPE,
ORDERED_KEY: False,
SOURCES_KEY: sources,
ENTRIES_KEY: entries,
}
)
|
Summarize one row of reading_lists_list.
Source code in comicbox/readinglists/formats/metron_api.py
90
91
92
93
94
95
96
97
98
99
100
101
102
103 | def summary_from_metron(row: ReadingListList) -> MetronListSummary:
"""Summarize one row of ``reading_lists_list``."""
curator = row.attribution_source
return MetronListSummary(
id=row.id,
name=row.name,
list_type=row.list_type,
private=row.is_private,
curator=curator.value.lower() if curator else None,
username=row.user.username,
rating=row.average_rating,
rating_count=row.rating_count,
modified=row.modified,
)
|