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

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['images']
 
bool paging = True
 
str endpoint = 'photos'
 
str base_url = 'https://loc.gov'
 
str search_string = "/{endpoint}/?sp={page}&{query}&fo=json"
 

Detailed Description

Library of Congress: query Photo, Print and Drawing from API endpoint_
``photos``.

.. _endpoint: https://www.loc.gov/apis/json-and-yaml/requests/endpoints/

.. note::

   Beside the ``photos`` endpoint_ there are more endpoints available / we are
   looking forward for contributions implementing more endpoints.

Function Documentation

◆ request()

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

Definition at line 34 of file loc.py.

34def request(query, params):
35
36 search_path = search_string.format(
37 endpoint=endpoint,
38 query=urlencode({'q': query}),
39 page=params['pageno'],
40 )
41 params['url'] = base_url + search_path
42 params['raise_for_httperror'] = False
43 return params
44
45

◆ response()

searx.engines.loc.response ( resp)

Definition at line 46 of file loc.py.

46def response(resp):
47
48 results = []
49 json_data = resp.json()
50
51 json_results = json_data.get('results')
52 if not json_results:
53 # when a search term has none results, loc sends a JSON in a HTTP 404
54 # response and the HTTP status code is set in the 'status' element.
55 if json_data.get('status') == 404:
56 return results
57
58 raise_for_httperror(resp)
59
60 for result in json_results:
61
62 url = result["item"].get("link")
63 if not url:
64 continue
65
66 img_src = result['item'].get('service_medium')
67 if not img_src or img_src == 'https://memory.loc.gov/pp/grp.gif':
68 continue
69
70 title = result['title']
71 if title.startswith('['):
72 title = title.strip('[]')
73
74 content_items = [
75 result['item'].get('created_published_date'),
76 result['item'].get('summary', [None])[0],
77 result['item'].get('notes', [None])[0],
78 result['item'].get('part_of', [None])[0],
79 ]
80
81 author = None
82 if result['item'].get('creators'):
83 author = result['item']['creators'][0]['title']
84
85 results.append(
86 {
87 'template': 'images.html',
88 'url': url,
89 'title': title,
90 'content': ' / '.join([i for i in content_items if i]),
91 'img_src': img_src,
92 'thumbnail_src': result['item'].get('thumb_gallery'),
93 'author': author,
94 }
95 )
96
97 return results

Variable Documentation

◆ about

dict searx.engines.loc.about
Initial value:
1= {
2 "website": 'https://www.loc.gov/pictures/',
3 "wikidata_id": 'Q131454',
4 "official_api_documentation": 'https://www.loc.gov/api',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 17 of file loc.py.

◆ base_url

str searx.engines.loc.base_url = 'https://loc.gov'

Definition at line 30 of file loc.py.

◆ categories

list searx.engines.loc.categories = ['images']

Definition at line 26 of file loc.py.

◆ endpoint

str searx.engines.loc.endpoint = 'photos'

Definition at line 29 of file loc.py.

◆ paging

bool searx.engines.loc.paging = True

Definition at line 27 of file loc.py.

◆ search_string

str searx.engines.loc.search_string = "/{endpoint}/?sp={page}&{query}&fo=json"

Definition at line 31 of file loc.py.