.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.openlibrary Namespace Reference

Functions

None request (str query, "OnlineParams" params)
EngineResults response ("SXNG_Response" resp)
datetime|None _parse_date (str date)

Variables

dict about
bool paging = True
list categories = ["general", "books"]
str base_url = "https://openlibrary.org"
str search_api = "https://openlibrary.org/search.json"
int results_per_page = 10

Detailed Description

`Open Library`_ is an open, editable library catalog, building towards a web
page for every book ever published.

.. _Open Library: https://openlibrary.org

Configuration
=============

The service sometimes takes a very long time to respond, the ``timeout`` may
need to be adjusted.

.. code:: yaml

  - name: openlibrary
    engine: openlibrary
    shortcut: ol
    timeout: 10


Implementations
===============

Function Documentation

◆ _parse_date()

datetime | None searx.engines.openlibrary._parse_date ( str date)
protected

Definition at line 103 of file openlibrary.py.

103def _parse_date(date: str) -> datetime | None:
104 if not date:
105 return None
106 try:
107 return parser.parse(date)
108 except parser.ParserError:
109 return None

Referenced by response().

Here is the caller graph for this function:

◆ request()

None searx.engines.openlibrary.request ( str query,
"OnlineParams" params )

Definition at line 58 of file openlibrary.py.

58def request(query: str, params: "OnlineParams") -> None:
59 args = {
60 "q": query,
61 "page": params["pageno"],
62 "limit": results_per_page,
63 "fields": "*",
64 }
65 params["url"] = f"{search_api}?{urlencode(args)}"
66 logger.debug("REST API: %s", params["url"])
67
68

◆ response()

EngineResults searx.engines.openlibrary.response ( "SXNG_Response" resp)

Definition at line 69 of file openlibrary.py.

69def response(resp: "SXNG_Response") -> EngineResults:
70 res = EngineResults()
71 json_data = resp.json()
72
73 for item in json_data.get("docs", []):
74 cover = ""
75 if "lending_identifier_s" in item:
76 cover = f"https://archive.org/services/img/{item['lending_identifier_s']}"
77
78 published = item.get("publish_date")
79 if published:
80 published_dates = [date for date in map(_parse_date, published) if date]
81 if published_dates:
82 published = min(published_dates)
83
84 if not published:
85 published = _parse_date(str(item.get("first_publish_year")))
86
87 content = " / ".join(item.get("first_sentence", []))
88 res.add(
89 res.types.Paper(
90 url=f"{base_url}/{item['key']}",
91 title=item["title"],
92 content=content,
93 isbn=item.get("isbn", [])[:5],
94 authors=item.get("author_name", []),
95 thumbnail=cover,
96 publishedDate=published,
97 tags=item.get("subject", [])[:10] + item.get("place", [])[:10],
98 )
99 )
100 return res
101
102

References _parse_date().

Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.openlibrary.about
Initial value:
1= {
2 "website": "https://openlibrary.org",
3 "wikidata_id": "Q1201876",
4 "require_api_key": False,
5 "use_official_api": False,
6 "official_api_documentation": "https://openlibrary.org/developers/api",
7}

Definition at line 38 of file openlibrary.py.

◆ base_url

str searx.engines.openlibrary.base_url = "https://openlibrary.org"

Definition at line 49 of file openlibrary.py.

◆ categories

list searx.engines.openlibrary.categories = ["general", "books"]

Definition at line 47 of file openlibrary.py.

◆ paging

bool searx.engines.openlibrary.paging = True

Definition at line 46 of file openlibrary.py.

◆ results_per_page

int searx.engines.openlibrary.results_per_page = 10

Definition at line 55 of file openlibrary.py.

◆ search_api

str searx.engines.openlibrary.search_api = "https://openlibrary.org/search.json"

Definition at line 50 of file openlibrary.py.