Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[upd] npm: Bump eslint from 8.57.0 to 9.0.0 in /searx/static/themes/simple #310

Closed
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ max_line_length = 119
[*.html]
indent_size = 4

[*.js]
indent_size = 2

[*.json]
indent_size = 4
insert_final_newline = ignore
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"eslint": "^8.50.0",
"eslint": "^9.0.0",
"pyright": "^1.1.329"
},
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion searx/engines/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Engine Configuration
categories = ['general']
paging = True
max_page = 5

# Base URL
base_url = "https://www.ask.com/web"
Expand Down Expand Up @@ -61,7 +62,7 @@ def response(resp):

results.append(
{
"url": item['url'],
"url": item['url'].split('&ueid')[0],
"title": item['title'],
"content": item['abstract'],
"publishedDate": pubdate_original,
Expand Down
20 changes: 13 additions & 7 deletions searx/engines/duckduckgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def get_vqd(query):
value = value[: value.index('"')]
break
logger.debug("new vqd value: '%s'", value)
cache_vqd(query, value)
if value is not None:
cache_vqd(query, value)
return value


Expand Down Expand Up @@ -221,21 +222,26 @@ def get_ddg_lang(eng_traits: EngineTraits, sxng_locale, default='en_US'):
}


def request(query, params):

# request needs a vqd argument
vqd = get_vqd(query)

def quote_ddg_bangs(query):
# quote ddg bangs
query_parts = []

# for val in re.split(r'(\s+)', query):
for val in re.split(r'(\s+)', query):
if not val.strip():
continue
if val.startswith('!') and external_bang.get_node(external_bang.EXTERNAL_BANGS, val[1:]):
val = f"'{val}'"
query_parts.append(val)
query = ' '.join(query_parts)
return ' '.join(query_parts)


def request(query, params):

query = quote_ddg_bangs(query)

# request needs a vqd argument
vqd = get_vqd(query)

eng_region = traits.get_region(params['searxng_locale'], traits.all_locale)
# eng_lang = get_ddg_lang(traits, params['searxng_locale'])
Expand Down
5 changes: 2 additions & 3 deletions searx/engines/mwmbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@

about = {
"website": 'https://github.com/mwmbl/mwmbl',
"official_api_documentation": 'https://api.mwmbl.org/docs',
"use_official_api": True,
"require_api_key": False,
"results": 'JSON',
}
paging = False
categories = ['general']

api_url = "https://api.mwmbl.org"
api_url = "https://api.mwmbl.org/api/v1"


def request(query, params):
params['url'] = f"{api_url}/search?{urlencode({'s': query})}"
params['url'] = f"{api_url}/search/?{urlencode({'s': query})}"
return params


Expand Down
118 changes: 118 additions & 0 deletions searx/engines/open_meteo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Open Meteo (weather)"""

from urllib.parse import urlencode, quote_plus
from datetime import datetime
from flask_babel import gettext

from searx.network import get
from searx.exceptions import SearxEngineAPIException

about = {
"website": 'https://open-meteo.com',
"wikidata_id": None,
"official_api_documentation": 'https://open-meteo.com/en/docs',
"use_official_api": True,
"require_api_key": False,
"results": "JSON",
}

categories = ["weather"]

geo_url = "https://geocoding-api.open-meteo.com"
api_url = "https://api.open-meteo.com"

data_of_interest = "temperature_2m,relative_humidity_2m,apparent_temperature,cloud_cover,pressure_msl,wind_speed_10m,wind_direction_10m" # pylint: disable=line-too-long


def request(query, params):
location_url = f"{geo_url}/v1/search?name={quote_plus(query)}"

resp = get(location_url)
if resp.status_code != 200:
raise SearxEngineAPIException("invalid geo location response code")

json_locations = resp.json().get("results", [])
if len(json_locations) == 0:
raise SearxEngineAPIException("location not found")

location = json_locations[0]
args = {
'latitude': location['latitude'],
'longitude': location['longitude'],
'timeformat': 'unixtime',
'format': 'json',
'current': data_of_interest,
'forecast_days': 7,
'hourly': data_of_interest,
}

params['url'] = f"{api_url}/v1/forecast?{urlencode(args)}"

return params


def c_to_f(temperature):
return "%.2f" % ((temperature * 1.8) + 32)


def get_direction(degrees):
if degrees < 45 or degrees >= 315:
return "N"

if 45 <= degrees < 135:
return "O"

if 135 <= degrees < 225:
return "S"

return "W"


def generate_condition_table(condition):
res = ""

res += (
f"<tr><td><b>{gettext('Temperature')}</b></td>"
f"<td><b>{condition['temperature_2m']}°C / {c_to_f(condition['temperature_2m'])}°F</b></td></tr>"
)

res += (
f"<tr><td>{gettext('Feels like')}</td><td>{condition['apparent_temperature']}°C / "
f"{c_to_f(condition['apparent_temperature'])}°F</td></tr>"
)

res += (
f"<tr><td>{gettext('Wind')}</td><td>{get_direction(condition['wind_direction_10m'])}, "
f"{condition['wind_direction_10m']}° — "
f"{condition['wind_speed_10m']} km/h</td></tr>"
)

res += f"<tr><td>{gettext('Cloud cover')}</td><td>{condition['cloud_cover']}%</td>"

res += f"<tr><td>{gettext('Humidity')}</td><td>{condition['relative_humidity_2m']}%</td></tr>"

res += f"<tr><td>{gettext('Pressure')}</td><td>{condition['pressure_msl']}hPa</td></tr>"

return res


def response(resp):
data = resp.json()

table_content = generate_condition_table(data['current'])

infobox = f"<table><tbody>{table_content}</tbody></table>"

for index, time in enumerate(data['hourly']['time']):
hourly_data = {}

for key in data_of_interest.split(","):
hourly_data[key] = data['hourly'][key][index]

table_content = generate_condition_table(hourly_data)

infobox += f"<h3>{datetime.utcfromtimestamp(time).strftime('%Y-%m-%d %H:%M')}</h3>"
infobox += f"<table><tbody>{table_content}</tbody></table>"

return [{'infobox': 'Open Meteo', 'content': infobox}]
10 changes: 7 additions & 3 deletions searx/limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,16 @@ def initialize(app: flask.Flask, settings):
"""Install the limiter"""
global _INSTALLED # pylint: disable=global-statement

# even if the limiter is not activated, the botdetection must be activated
# (e.g. the self_info plugin uses the botdetection to get client IP)

cfg = get_cfg()
redis_client = redisdb.client()
botdetection.init(cfg, redis_client)

if not (settings['server']['limiter'] or settings['server']['public_instance']):
return

redis_client = redisdb.client()
if not redis_client:
logger.error(
"The limiter requires Redis, please consult the documentation: "
Expand All @@ -233,10 +239,8 @@ def initialize(app: flask.Flask, settings):

_INSTALLED = True

cfg = get_cfg()
if settings['server']['public_instance']:
# overwrite limiter.toml setting
cfg.set('botdetection.ip_limit.link_token', True)

botdetection.init(cfg, redis_client)
app.before_request(pre_request)
5 changes: 5 additions & 0 deletions searx/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,11 @@ engines:
require_api_key: false
results: JSON

- name: openmeteo
engine: open_meteo
shortcut: om
disabled: true

# - name: opensemanticsearch
# engine: opensemantic
# shortcut: oss
Expand Down
2 changes: 1 addition & 1 deletion searx/static/themes/simple/img/img_load_error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion searx/static/themes/simple/img/searxng.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion searx/static/themes/simple/js/searxng.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searx/static/themes/simple/js/searxng.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searx/static/themes/simple/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devDependencies": {
"eslint": "^8.18.0",
"eslint": "^9.0.0",
"grunt": "~1.6.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^5.0.0",
Expand Down
Loading
Loading