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

Functions

 request (query, params)
 
 _parse_date (date)
 
 response (resp)
 

Variables

dict about
 
bool paging = True
 
list categories = []
 
str base_url = "https://openlibrary.org"
 
int results_per_page = 10
 

Detailed Description

Open library (books)

Function Documentation

◆ _parse_date()

searx.engines.openlibrary._parse_date ( date)
protected

Definition at line 34 of file openlibrary.py.

34def _parse_date(date):
35 try:
36 return parser.parse(date)
37 except parser.ParserError:
38 return None
39
40

◆ request()

searx.engines.openlibrary.request ( query,
params )

Definition at line 24 of file openlibrary.py.

24def request(query, params):
25 args = {
26 'q': query,
27 'page': params['pageno'],
28 'limit': results_per_page,
29 }
30 params['url'] = f"{base_url}/search.json?{urlencode(args)}"
31 return params
32
33

◆ response()

searx.engines.openlibrary.response ( resp)

Definition at line 41 of file openlibrary.py.

41def response(resp):
42 results = []
43
44 for item in resp.json().get("docs", []):
45 cover = None
46 if 'lending_identifier_s' in item:
47 cover = f"https://archive.org/services/img/{item['lending_identifier_s']}"
48
49 published = item.get('publish_date')
50 if published:
51 published_dates = [date for date in map(_parse_date, published) if date]
52 if published_dates:
53 published = min(published_dates)
54
55 if not published:
56 published = parser.parse(str(item.get('first_published_year')))
57
58 result = {
59 'template': 'paper.html',
60 'url': f"{base_url}{item['key']}",
61 'title': item['title'],
62 'content': re.sub(r"\{|\}", "", item['first_sentence'][0]) if item.get('first_sentence') else '',
63 'isbn': item.get('isbn', [])[:5],
64 'authors': item.get('author_name', []),
65 'thumbnail': cover,
66 'publishedDate': published,
67 'tags': item.get('subject', [])[:10] + item.get('place', [])[:10],
68 }
69 results.append(result)
70
71 return results

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 9 of file openlibrary.py.

◆ base_url

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

Definition at line 20 of file openlibrary.py.

◆ categories

list searx.engines.openlibrary.categories = []

Definition at line 18 of file openlibrary.py.

◆ paging

bool searx.engines.openlibrary.paging = True

Definition at line 17 of file openlibrary.py.

◆ results_per_page

int searx.engines.openlibrary.results_per_page = 10

Definition at line 21 of file openlibrary.py.