.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
wallhaven.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Wallhaven_ is a site created by and for people who like wallpapers.
3
4
.. _Wallhaven: https://wallhaven.cc/about#Copyright
5
"""
6
7
from
datetime
import
datetime
8
from
urllib.parse
import
urlencode
9
10
from
searx.utils
import
humanize_bytes
11
12
about = {
13
'website'
:
'https://wallhaven.cc/'
,
14
'official_api_documentation'
:
'https://wallhaven.cc/help/api'
,
15
'use_official_api'
:
True
,
16
'require_api_key'
:
False
,
17
'results'
:
'JSON'
,
18
}
19
categories = [
'images'
]
20
paging =
True
21
22
base_url =
"https://wallhaven.cc"
23
24
api_key =
''
25
"""If you own an API key you can add it here, further read `Rate Limiting and
26
Errors`_.
27
28
.. _Rate Limiting and Errors: https://wallhaven.cc/help/api#limits
29
30
"""
31
32
# Possible categories: sfw, sketchy, nsfw
33
safesearch_map = {0:
'111'
, 1:
'110'
, 2:
'100'
}
34
"""Turn purities on(1) or off(0) NSFW requires a valid API key.
35
36
.. code:: text
37
38
100/110/111 <-- Bits stands for: SFW, Sketchy and NSFW
39
40
`What are SFW, Sketchy and NSFW all about?`_:
41
42
- SFW = "Safe for work" wallpapers. *Grandma approves.*
43
- Sketchy = Not quite SFW not quite NSFW. *Grandma might be uncomfortable.*
44
- NSFW = "Not safe for work". *Grandma isn't sure who you are anymore.*
45
46
.. _What are SFW, Sketchy and NSFW all about?:
47
https://wallhaven.cc/faq#What-are-SFW-Sketchy-and-NSFW-all-about
48
49
"""
50
51
52
def
request
(query, params):
53
args = {
54
'q'
: query,
55
'page'
: params[
'pageno'
],
56
'purity'
: safesearch_map[params[
'safesearch'
]],
57
}
58
59
if
api_key:
60
params[
'api_key'
] = api_key
61
62
params[
'url'
] = f
"{base_url}/api/v1/search?{urlencode(args)}"
63
return
params
64
65
66
def
response
(resp):
67
results = []
68
69
json = resp.json()
70
71
for
result
in
json[
'data'
]:
72
73
results.append(
74
{
75
'template'
:
'images.html'
,
76
'title'
:
''
,
77
'content'
: f
"{result['category']} / {result['purity']}"
,
78
'url'
: result[
'url'
],
79
'img_src'
: result[
'path'
],
80
'thumbnail_src'
: result[
'thumbs'
][
'small'
],
81
'resolution'
: result[
'resolution'
].replace(
'x'
,
' x '
),
82
'publishedDate'
: datetime.strptime(result[
'created_at'
],
'%Y-%m-%d %H:%M:%S'
),
83
'img_format'
: result[
'file_type'
],
84
'filesize'
: humanize_bytes(result[
'file_size'
]),
85
}
86
)
87
88
return
results
searx.engines.wallhaven.request
request(query, params)
Definition
wallhaven.py:52
searx.engines.wallhaven.response
response(resp)
Definition
wallhaven.py:66
searx.utils
Definition
utils.py:1
searxng
searx
engines
wallhaven.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0