mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
adds more random options
This commit is contained in:
parent
527f680087
commit
9ab55ea47a
2 changed files with 26 additions and 3 deletions
|
@ -23,8 +23,8 @@ def get_answerers_by_keywords(answerers):
|
||||||
by_keyword = defaultdict(list)
|
by_keyword = defaultdict(list)
|
||||||
for answerer in answerers:
|
for answerer in answerers:
|
||||||
for keyword in answerer.keywords:
|
for keyword in answerer.keywords:
|
||||||
for keyword in answerer.keywords:
|
# for keyword in answerer.keywords:
|
||||||
by_keyword[keyword].append(answerer.answer)
|
by_keyword[keyword].append(answerer.answer)
|
||||||
return by_keyword
|
return by_keyword
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from flask_babel import gettext
|
||||||
|
|
||||||
# required answerer attribute
|
# required answerer attribute
|
||||||
# specifies which search query keywords triggers this answerer
|
# specifies which search query keywords triggers this answerer
|
||||||
keywords = ('random',)
|
keywords = ('random', 'rand', '!r')
|
||||||
|
|
||||||
random_int_max = 2**31
|
random_int_max = 2**31
|
||||||
random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
|
random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
|
||||||
|
@ -42,6 +42,20 @@ def random_color():
|
||||||
color = "%06x" % random.randint(0, 0xFFFFFF)
|
color = "%06x" % random.randint(0, 0xFFFFFF)
|
||||||
return f"#{color.upper()}"
|
return f"#{color.upper()}"
|
||||||
|
|
||||||
|
def random_number(x: int):
|
||||||
|
return str(random.randint(1, x))
|
||||||
|
|
||||||
|
def random_coin():
|
||||||
|
return random.choice(['heads', 'tails'])
|
||||||
|
|
||||||
|
def random_card():
|
||||||
|
return random.choice(['2', '3', '4', '5', '6', '7', '8', '9', '10', 'jack', 'queen', 'king', 'ace']) + ' of ' + random.choice(['diamonds', 'spades', 'hearts', 'clubs'])
|
||||||
|
|
||||||
|
def random_dice():
|
||||||
|
return str(random.randint(1, 6))
|
||||||
|
|
||||||
|
def random_d20():
|
||||||
|
return str(random.randint(1, 20))
|
||||||
|
|
||||||
random_types = {
|
random_types = {
|
||||||
'string': random_string,
|
'string': random_string,
|
||||||
|
@ -50,6 +64,10 @@ random_types = {
|
||||||
'sha256': random_sha256,
|
'sha256': random_sha256,
|
||||||
'uuid': random_uuid,
|
'uuid': random_uuid,
|
||||||
'color': random_color,
|
'color': random_color,
|
||||||
|
'coin': random_coin,
|
||||||
|
'card': random_card,
|
||||||
|
'dice': random_dice,
|
||||||
|
'd20': random_d20,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,6 +79,11 @@ def answer(query):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if parts[1] not in random_types:
|
if parts[1] not in random_types:
|
||||||
|
try:
|
||||||
|
if parts[1].isnumeric():
|
||||||
|
return [{'answer': random_number(int(parts[1]))}]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return [{'answer': random_types[parts[1]]()}]
|
return [{'answer': random_types[parts[1]]()}]
|
||||||
|
|
Loading…
Add table
Reference in a new issue