.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_config_url = 'https://pdimagearchive.org/_astro/config.BiNvrvzG.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 52 of file public_domain_image_archive.py.

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

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 78 of file public_domain_image_archive.py.

78def _clear_cached_api_key():
79 global __CACHED_API_KEY # pylint:disable=global-statement
80
81 __CACHED_API_KEY = None
82
83

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 59 of file public_domain_image_archive.py.

59def _get_algolia_api_key():
60 global __CACHED_API_KEY # pylint:disable=global-statement
61
62 if __CACHED_API_KEY:
63 return __CACHED_API_KEY
64
65 resp = get(pdia_config_url)
66 if resp.status_code != 200:
67 raise LookupError("Failed to obtain Algolia API key for PDImageArchive")
68
69 api_key = extr(resp.text, 'r="', '"', default=None)
70
71 if api_key is None:
72 raise LookupError("Couldn't obtain Algolia API key for PDImageArchive")
73
74 __CACHED_API_KEY = api_key
75 return api_key
76
77

Referenced by request().

+ Here is the caller graph for this function:

◆ request()

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

Definition at line 84 of file public_domain_image_archive.py.

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

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 112 of file public_domain_image_archive.py.

112def response(resp):
113 results = []
114 json_data = resp.json()
115
116 if resp.status_code == 403:
117 _clear_cached_api_key()
118 raise SearxEngineAccessDeniedException()
119
120 if resp.status_code != 200:
121 raise SearxEngineException()
122
123 if 'results' not in json_data:
124 return []
125
126 for result in json_data['results'][0]['hits']:
127 content = []
128
129 if "themes" in result:
130 content.append("Themes: " + result['themes'])
131
132 if "encompassingWork" in result:
133 content.append("Encompassing work: " + result['encompassingWork'])
134 content = "\n".join(content)
135
136 base_image_url = result['thumbnail'].split("?")[0]
137
138 results.append(
139 {
140 'template': 'images.html',
141 'url': _clean_url(f"{about['website']}/images/{result['objectID']}"),
142 'img_src': _clean_url(base_image_url),
143 'thumbnail_src': _clean_url(base_image_url + THUMBNAIL_SUFFIX),
144 'title': f"{result['title'].strip()} by {result['artist']} {result.get('displayYear', '')}",
145 'content': content,
146 }
147 )
148
149 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 49 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 44 of file public_domain_image_archive.py.

◆ page_size

int searx.engines.public_domain_image_archive.page_size = 20

Definition at line 45 of file public_domain_image_archive.py.

◆ paging

bool searx.engines.public_domain_image_archive.paging = True

Definition at line 46 of file public_domain_image_archive.py.

◆ pdia_config_url

str searx.engines.public_domain_image_archive.pdia_config_url = 'https://pdimagearchive.org/_astro/config.BiNvrvzG.js'

Definition at line 43 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.