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

Functions

 _clean_url (url)
 
 _get_algolia_api_key ()
 
 _clear_cached_api_key ()
 
 request (query, params)
 
 response (resp)
 

Variables

str THUMBNAIL_SUFFIX = "?fit=max&h=360&w=360"
 
dict about
 
str base_url = 'https://oqi2j6v4iz-dsn.algolia.net'
 
str pdia_base_url = 'https://pdimagearchive.org'
 
str pdia_search_url = pdia_base_url + '/search/?q='
 
str pdia_config_start = "/_astro/InfiniteSearch."
 
str pdia_config_end = ".js"
 
list categories = ['images']
 
int page_size = 20
 
bool paging = True
 
 __CACHED_API_KEY = None
 

Detailed Description

Public domain image archive

Function Documentation

◆ _clean_url()

searx.engines.public_domain_image_archive._clean_url ( url)
protected

Definition at line 55 of file public_domain_image_archive.py.

55def _clean_url(url):
56 parsed = urlparse(url)
57 query = [(k, v) for (k, v) in parse_qsl(parsed.query) if k not in ['ixid', 's']]
58
59 return urlunparse((parsed.scheme, parsed.netloc, parsed.path, parsed.params, urlencode(query), parsed.fragment))
60
61

Referenced by response().

+ Here is the caller graph for this function:

◆ _clear_cached_api_key()

searx.engines.public_domain_image_archive._clear_cached_api_key ( )
protected

Definition at line 87 of file public_domain_image_archive.py.

87def _clear_cached_api_key():
88 global __CACHED_API_KEY # pylint:disable=global-statement
89
90 __CACHED_API_KEY = None
91
92

Referenced by response().

+ Here is the caller graph for this function:

◆ _get_algolia_api_key()

searx.engines.public_domain_image_archive._get_algolia_api_key ( )
protected

Definition at line 62 of file public_domain_image_archive.py.

62def _get_algolia_api_key():
63 global __CACHED_API_KEY # pylint:disable=global-statement
64
65 if __CACHED_API_KEY:
66 return __CACHED_API_KEY
67
68 resp = get(pdia_search_url)
69 if resp.status_code != 200:
70 raise LookupError("Failed to fetch config location (and as such the API key) for PDImageArchive")
71 pdia_config_filepart = extr(resp.text, pdia_config_start, pdia_config_end)
72 pdia_config_url = pdia_base_url + pdia_config_start + pdia_config_filepart + pdia_config_end
73
74 resp = get(pdia_config_url)
75 if resp.status_code != 200:
76 raise LookupError("Failed to obtain Algolia API key for PDImageArchive")
77
78 api_key = extr(resp.text, 'const r="', '"', default=None)
79
80 if api_key is None:
81 raise LookupError("Couldn't obtain Algolia API key for PDImageArchive")
82
83 __CACHED_API_KEY = api_key
84 return api_key
85
86

Referenced by request().

+ Here is the caller graph for this function:

◆ request()

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

Definition at line 93 of file public_domain_image_archive.py.

93def request(query, params):
94 api_key = _get_algolia_api_key()
95
96 args = {
97 'x-algolia-api-key': api_key,
98 'x-algolia-application-id': 'OQI2J6V4IZ',
99 }
100 params['url'] = f"{base_url}/1/indexes/*/queries?{urlencode(args)}"
101 params["method"] = "POST"
102
103 request_params = {
104 "page": params["pageno"] - 1,
105 "query": query,
106 "highlightPostTag": "__ais-highlight__",
107 "highlightPreTag": "__ais-highlight__",
108 }
109 data = {
110 "requests": [
111 {"indexName": "prod_all-images", "params": urlencode(request_params)},
112 ]
113 }
114 params["data"] = dumps(data)
115
116 # http errors are handled manually to be able to reset the api key
117 params['raise_for_httperror'] = False
118 return params
119
120

References _get_algolia_api_key().

+ Here is the call graph for this function:

◆ response()

searx.engines.public_domain_image_archive.response ( resp)

Definition at line 121 of file public_domain_image_archive.py.

121def response(resp):
122 results = []
123 json_data = resp.json()
124
125 if resp.status_code == 403:
126 _clear_cached_api_key()
127 raise SearxEngineAccessDeniedException()
128
129 if resp.status_code != 200:
130 raise SearxEngineException()
131
132 if 'results' not in json_data:
133 return []
134
135 for result in json_data['results'][0]['hits']:
136 content = []
137
138 if "themes" in result:
139 content.append("Themes: " + result['themes'])
140
141 if "encompassingWork" in result:
142 content.append("Encompassing work: " + result['encompassingWork'])
143 content = "\n".join(content)
144
145 base_image_url = result['thumbnail'].split("?")[0]
146
147 results.append(
148 {
149 'template': 'images.html',
150 'url': _clean_url(f"{about['website']}/images/{result['objectID']}"),
151 'img_src': _clean_url(base_image_url),
152 'thumbnail_src': _clean_url(base_image_url + THUMBNAIL_SUFFIX),
153 'title': f"{result['title'].strip()} by {result['artist']} {result.get('displayYear', '')}",
154 'content': content,
155 }
156 )
157
158 return results

References _clean_url(), and _clear_cached_api_key().

+ Here is the call graph for this function:

Variable Documentation

◆ __CACHED_API_KEY

searx.engines.public_domain_image_archive.__CACHED_API_KEY = None
private

Definition at line 52 of file public_domain_image_archive.py.

◆ about

dict searx.engines.public_domain_image_archive.about
Initial value:
1= {
2 "website": 'https://pdimagearchive.org',
3 "use_official_api": False,
4 "require_api_key": False,
5 "results": 'JSON',
6}

Definition at line 35 of file public_domain_image_archive.py.

◆ base_url

str searx.engines.public_domain_image_archive.base_url = 'https://oqi2j6v4iz-dsn.algolia.net'

Definition at line 42 of file public_domain_image_archive.py.

◆ categories

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

Definition at line 47 of file public_domain_image_archive.py.

◆ page_size

int searx.engines.public_domain_image_archive.page_size = 20

Definition at line 48 of file public_domain_image_archive.py.

◆ paging

bool searx.engines.public_domain_image_archive.paging = True

Definition at line 49 of file public_domain_image_archive.py.

◆ pdia_base_url

str searx.engines.public_domain_image_archive.pdia_base_url = 'https://pdimagearchive.org'

Definition at line 43 of file public_domain_image_archive.py.

◆ pdia_config_end

str searx.engines.public_domain_image_archive.pdia_config_end = ".js"

Definition at line 46 of file public_domain_image_archive.py.

◆ pdia_config_start

str searx.engines.public_domain_image_archive.pdia_config_start = "/_astro/InfiniteSearch."

Definition at line 45 of file public_domain_image_archive.py.

◆ pdia_search_url

str searx.engines.public_domain_image_archive.pdia_search_url = pdia_base_url + '/search/?q='

Definition at line 44 of file public_domain_image_archive.py.

◆ THUMBNAIL_SUFFIX

str searx.engines.public_domain_image_archive.THUMBNAIL_SUFFIX = "?fit=max&h=360&w=360"

Definition at line 11 of file public_domain_image_archive.py.