.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
answerer.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
# pylint: disable=missing-module-docstring
3
4
import
hashlib
5
import
random
6
import
string
7
import
uuid
8
from
flask_babel
import
gettext
9
10
# required answerer attribute
11
# specifies which search query keywords triggers this answerer
12
keywords = (
'random'
,)
13
14
random_int_max = 2**31
15
random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
16
17
18
def
random_characters
():
19
return
[random.choice(random_string_letters)
for
_
in
range(random.randint(8, 32))]
20
21
22
def
random_string
():
23
return
''
.join(
random_characters
())
24
25
26
def
random_float
():
27
return
str(random.random())
28
29
30
def
random_int
():
31
return
str(random.randint(-random_int_max, random_int_max))
32
33
34
def
random_sha256
():
35
m = hashlib.sha256()
36
m.update(
''
.join(
random_characters
()).encode())
37
return
str(m.hexdigest())
38
39
40
def
random_uuid
():
41
return
str(uuid.uuid4())
42
43
44
def
random_color
():
45
color =
"%06x"
% random.randint(0, 0xFFFFFF)
46
return
f
"#{color.upper()}"
47
48
49
random_types = {
50
'string'
: random_string,
51
'int'
: random_int,
52
'float'
: random_float,
53
'sha256'
: random_sha256,
54
'uuid'
: random_uuid,
55
'color'
: random_color,
56
}
57
58
59
# required answerer function
60
# can return a list of results (any result type) for a given query
61
def
answer
(query):
62
parts = query.query.split()
63
if
len(parts) != 2:
64
return
[]
65
66
if
parts[1]
not
in
random_types:
67
return
[]
68
69
return
[{
'answer'
: random_types[parts[1]]()}]
70
71
72
# required answerer function
73
# returns information about the answerer
74
def
self_info
():
75
return
{
76
'name'
: gettext(
'Random value generator'
),
77
'description'
: gettext(
'Generate different random values'
),
78
'examples'
: [
'random {}'
.
format
(x)
for
x
in
random_types],
79
}
searx.answerers.random.answerer.random_characters
random_characters()
Definition
answerer.py:18
searx.answerers.random.answerer.random_sha256
random_sha256()
Definition
answerer.py:34
searx.answerers.random.answerer.answer
answer(query)
Definition
answerer.py:61
searx.answerers.random.answerer.random_string
random_string()
Definition
answerer.py:22
searx.answerers.random.answerer.random_int
random_int()
Definition
answerer.py:30
searx.answerers.random.answerer.self_info
self_info()
Definition
answerer.py:74
searx.answerers.random.answerer.random_float
random_float()
Definition
answerer.py:26
searx.answerers.random.answerer.random_uuid
random_uuid()
Definition
answerer.py:40
searx.answerers.random.answerer.random_color
random_color()
Definition
answerer.py:44
searx.format
format
Definition
__init__.py:94
searxng
searx
answerers
random
answerer.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0