MCPcopy Create free account
hub / github.com/karpathy/reader3 / library_view

Function library_view

server.py:38–56  ·  view source on GitHub ↗

Lists all available processed books.

(request: Request)

Source from the content-addressed store, hash-verified

36
37@app.get("/", response_class=HTMLResponse)
38async def library_view(request: Request):
39 """Lists all available processed books."""
40 books = []
41
42 # Scan directory for folders ending in '_data' that have a book.pkl
43 if os.path.exists(BOOKS_DIR):
44 for item in os.listdir(BOOKS_DIR):
45 if item.endswith("_data") and os.path.isdir(item):
46 # Try to load it to get the title
47 book = load_book_cached(item)
48 if book:
49 books.append({
50 "id": item,
51 "title": book.metadata.title,
52 "author": ", ".join(book.metadata.authors),
53 "chapters": len(book.spine)
54 })
55
56 return templates.TemplateResponse("library.html", {"request": request, "books": books})
57
58@app.get("/read/{book_id}", response_class=HTMLResponse)
59async def redirect_to_first_chapter(book_id: str):

Callers

nothing calls this directly

Calls 1

load_book_cachedFunction · 0.85

Tested by

no test coverage detected