MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / format_work_data

Function format_work_data

openlibrary/plugins/openlibrary/code.py:311–330  ·  view source on GitHub ↗
(work)

Source from the content-addressed store, hash-verified

309
310
311def format_work_data(work):
312 d = dict(work)
313
314 key = work.get("key", "")
315 # New solr stores the key as /works/OLxxxW
316 if not key.startswith("/works/"):
317 key = "/works/" + key
318
319 d["url"] = key
320 d["title"] = work.get("title", "")
321
322 if "author_key" in work and "author_name" in work:
323 d["authors"] = [{"key": key, "name": name} for key, name in zip(work["author_key"], work["author_name"])]
324
325 if "cover_edition_key" in work:
326 coverstore_url = get_coverstore_public_url()
327 d["cover_url"] = f"{coverstore_url}/b/olid/{work['cover_edition_key']}-M.jpg"
328
329 d["read_url"] = "//archive.org/stream/" + work["ia"][0]
330 return d
331
332
333class addauthor(delegate.page):

Callers 1

GETMethod · 0.85

Calls 2

getMethod · 0.45

Tested by

no test coverage detected