.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
unsplash.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Unsplash
3
4
"""
5
6
from
urllib.parse
import
urlencode, urlparse, urlunparse, parse_qsl
7
from
json
import
loads
8
9
# about
10
about = {
11
"website"
:
'https://unsplash.com'
,
12
"wikidata_id"
:
'Q28233552'
,
13
"official_api_documentation"
:
'https://unsplash.com/developers'
,
14
"use_official_api"
:
False
,
15
"require_api_key"
:
False
,
16
"results"
:
'JSON'
,
17
}
18
19
base_url =
'https://unsplash.com/'
20
search_url = base_url +
'napi/search/photos?'
21
categories = [
'images'
]
22
page_size = 20
23
paging =
True
24
25
26
def
clean_url
(url):
27
parsed = urlparse(url)
28
query = [(k, v)
for
(k, v)
in
parse_qsl(parsed.query)
if
k
not
in
[
'ixid'
,
's'
]]
29
30
return
urlunparse((parsed.scheme, parsed.netloc, parsed.path, parsed.params, urlencode(query), parsed.fragment))
31
32
33
def
request
(query, params):
34
params[
'url'
] = search_url + urlencode({
'query'
: query,
'page'
: params[
'pageno'
],
'per_page'
: page_size})
35
logger.debug(
"query_url --> %s"
, params[
'url'
])
36
return
params
37
38
39
def
response
(resp):
40
results = []
41
json_data = loads(resp.text)
42
43
if
'results'
in
json_data:
44
for
result
in
json_data[
'results'
]:
45
results.append(
46
{
47
'template'
:
'images.html'
,
48
'url'
:
clean_url
(result[
'links'
][
'html'
]),
49
'thumbnail_src'
:
clean_url
(result[
'urls'
][
'thumb'
]),
50
'img_src'
:
clean_url
(result[
'urls'
][
'raw'
]),
51
'title'
: result.get(
'alt_description'
)
or
'unknown'
,
52
'content'
: result.get(
'description'
)
or
''
,
53
}
54
)
55
56
return
results
searx.engines.unsplash.request
request(query, params)
Definition
unsplash.py:33
searx.engines.unsplash.response
response(resp)
Definition
unsplash.py:39
searx.engines.unsplash.clean_url
clean_url(url)
Definition
unsplash.py:26
searxng
searx
engines
unsplash.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0