mirror of
https://github.com/searxng/searxng.git
synced 2026-07-25 17:31:23 +00:00
Compare commits
13 Commits
cce0957f54
...
update_dat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
872e838fa4 | ||
|
|
8605230eb8 | ||
|
|
a54722e692 | ||
|
|
7e9a6c2861 | ||
|
|
357662d86d | ||
|
|
bfa76e4cd9 | ||
|
|
a9d49a3349 | ||
|
|
f8ffbf36f9 | ||
|
|
e3126b89e6 | ||
|
|
f9f3d089ec | ||
|
|
e3713717f2 | ||
|
|
952896d29e | ||
|
|
4cc32b2457 |
6
.github/workflows/container.yml
vendored
6
.github/workflows/container.yml
vendored
@@ -73,7 +73,7 @@ jobs:
|
|||||||
# yamllint enable rule:line-length
|
# yamllint enable rule:line-length
|
||||||
|
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||||
with:
|
with:
|
||||||
python-version: "${{ env.PYTHON_VERSION }}"
|
python-version: "${{ env.PYTHON_VERSION }}"
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ jobs:
|
|||||||
fetch-depth: "0"
|
fetch-depth: "0"
|
||||||
|
|
||||||
- name: Setup cache Python
|
- name: Setup cache Python
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
@@ -96,7 +96,7 @@ jobs:
|
|||||||
run: echo "date=$(date +'%Y%m%d')" >>$GITHUB_OUTPUT
|
run: echo "date=$(date +'%Y%m%d')" >>$GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Setup cache container
|
- name: Setup cache container
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "container-${{ matrix.arch }}-${{ steps.date.outputs.date }}-${{ hashFiles('./requirements*.txt') }}"
|
key: "container-${{ matrix.arch }}-${{ steps.date.outputs.date }}-${{ hashFiles('./requirements*.txt') }}"
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
|
|||||||
4
.github/workflows/data-update.yml
vendored
4
.github/workflows/data-update.yml
vendored
@@ -41,7 +41,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||||
with:
|
with:
|
||||||
python-version: "${{ env.PYTHON_VERSION }}"
|
python-version: "${{ env.PYTHON_VERSION }}"
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ jobs:
|
|||||||
persist-credentials: "false"
|
persist-credentials: "false"
|
||||||
|
|
||||||
- name: Setup cache Python
|
- name: Setup cache Python
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
|
|||||||
4
.github/workflows/documentation.yml
vendored
4
.github/workflows/documentation.yml
vendored
@@ -32,7 +32,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||||
with:
|
with:
|
||||||
python-version: "${{ env.PYTHON_VERSION }}"
|
python-version: "${{ env.PYTHON_VERSION }}"
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ jobs:
|
|||||||
fetch-depth: "0"
|
fetch-depth: "0"
|
||||||
|
|
||||||
- name: Setup cache Python
|
- name: Setup cache Python
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
|
|||||||
10
.github/workflows/integration.yml
vendored
10
.github/workflows/integration.yml
vendored
@@ -34,7 +34,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||||
with:
|
with:
|
||||||
python-version: "${{ matrix.python-version }}"
|
python-version: "${{ matrix.python-version }}"
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ jobs:
|
|||||||
persist-credentials: "false"
|
persist-credentials: "false"
|
||||||
|
|
||||||
- name: Setup cache Python
|
- name: Setup cache Python
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "python-${{ matrix.python-version }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
key: "python-${{ matrix.python-version }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
@@ -62,7 +62,7 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04-arm
|
runs-on: ubuntu-24.04-arm
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||||
with:
|
with:
|
||||||
python-version: "${{ env.PYTHON_VERSION }}"
|
python-version: "${{ env.PYTHON_VERSION }}"
|
||||||
|
|
||||||
@@ -77,13 +77,13 @@ jobs:
|
|||||||
node-version-file: "./.nvmrc"
|
node-version-file: "./.nvmrc"
|
||||||
|
|
||||||
- name: Setup cache Node.js
|
- name: Setup cache Node.js
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "nodejs-${{ runner.arch }}-${{ hashFiles('./.nvmrc', './package.json') }}"
|
key: "nodejs-${{ runner.arch }}-${{ hashFiles('./.nvmrc', './package.json') }}"
|
||||||
path: "./client/simple/node_modules/"
|
path: "./client/simple/node_modules/"
|
||||||
|
|
||||||
- name: Setup cache Python
|
- name: Setup cache Python
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
|
|||||||
8
.github/workflows/l10n.yml
vendored
8
.github/workflows/l10n.yml
vendored
@@ -35,7 +35,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||||
with:
|
with:
|
||||||
python-version: "${{ env.PYTHON_VERSION }}"
|
python-version: "${{ env.PYTHON_VERSION }}"
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ jobs:
|
|||||||
fetch-depth: "0"
|
fetch-depth: "0"
|
||||||
|
|
||||||
- name: Setup cache Python
|
- name: Setup cache Python
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
@@ -83,7 +83,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||||
with:
|
with:
|
||||||
python-version: "${{ env.PYTHON_VERSION }}"
|
python-version: "${{ env.PYTHON_VERSION }}"
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ jobs:
|
|||||||
fetch-depth: "0"
|
fetch-depth: "0"
|
||||||
|
|
||||||
- name: Setup cache Python
|
- name: Setup cache Python
|
||||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
|
||||||
with:
|
with:
|
||||||
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
|
|||||||
2
.github/workflows/security.yml
vendored
2
.github/workflows/security.yml
vendored
@@ -29,7 +29,7 @@ jobs:
|
|||||||
persist-credentials: "false"
|
persist-credentials: "false"
|
||||||
|
|
||||||
- name: Sync GHCS from Docker Scout
|
- name: Sync GHCS from Docker Scout
|
||||||
uses: docker/scout-action@cd72f264beff1cd72735de31148b9d3244a0234a # v1.21.0
|
uses: docker/scout-action@7520205ff60037fdc436b40b6a1d1e55a839ec2d # v1.22.0
|
||||||
with:
|
with:
|
||||||
organization: "searxng"
|
organization: "searxng"
|
||||||
dockerhub-user: "${{ secrets.DOCKER_USER }}"
|
dockerhub-user: "${{ secrets.DOCKER_USER }}"
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -207,6 +207,7 @@ class EngineAbout(msgspec.Struct, kw_only=True):
|
|||||||
|
|
||||||
use_official_api: bool = False
|
use_official_api: bool = False
|
||||||
"""SearXNG engine makes use of the official API or not"""
|
"""SearXNG engine makes use of the official API or not"""
|
||||||
|
|
||||||
require_api_key: bool = False
|
require_api_key: bool = False
|
||||||
"""API requires a key or not."""
|
"""API requires a key or not."""
|
||||||
|
|
||||||
@@ -217,8 +218,7 @@ class EngineAbout(msgspec.Struct, kw_only=True):
|
|||||||
"""Brief description of the engine and where it gets its data from.
|
"""Brief description of the engine and where it gets its data from.
|
||||||
|
|
||||||
This value should only be set as long as no description of the data source
|
This value should only be set as long as no description of the data source
|
||||||
is available via a :py:obj:`EngineAbout.wikidata_id`.
|
is available via a :py:obj:`EngineAbout.wikidata_id`."""
|
||||||
"""
|
|
||||||
|
|
||||||
language: str = ""
|
language: str = ""
|
||||||
"""Deprecated! Migrate your setting from `engine.about.language` to
|
"""Deprecated! Migrate your setting from `engine.about.language` to
|
||||||
|
|||||||
@@ -19,11 +19,9 @@ Configuration
|
|||||||
|
|
||||||
The engine has the following additional settings:
|
The engine has the following additional settings:
|
||||||
|
|
||||||
- :py:obj:`chinaso_category` (:py:obj:`ChinasoCategoryType`)
|
|
||||||
- :py:obj:`chinaso_news_source` (:py:obj:`ChinasoNewsSourceType`)
|
- :py:obj:`chinaso_news_source` (:py:obj:`ChinasoNewsSourceType`)
|
||||||
|
|
||||||
In the example below, all three ChinaSO engines are using the :ref:`network
|
In the example below, ChinaSO is configured for news search.
|
||||||
<engine network>` from the ``chinaso news`` engine.
|
|
||||||
|
|
||||||
.. code:: yaml
|
.. code:: yaml
|
||||||
|
|
||||||
@@ -31,23 +29,8 @@ In the example below, all three ChinaSO engines are using the :ref:`network
|
|||||||
engine: chinaso
|
engine: chinaso
|
||||||
shortcut: chinaso
|
shortcut: chinaso
|
||||||
categories: [news]
|
categories: [news]
|
||||||
chinaso_category: news
|
|
||||||
chinaso_news_source: all
|
chinaso_news_source: all
|
||||||
|
|
||||||
- name: chinaso images
|
|
||||||
engine: chinaso
|
|
||||||
network: chinaso news
|
|
||||||
shortcut: chinasoi
|
|
||||||
categories: [images]
|
|
||||||
chinaso_category: images
|
|
||||||
|
|
||||||
- name: chinaso videos
|
|
||||||
engine: chinaso
|
|
||||||
network: chinaso news
|
|
||||||
shortcut: chinasov
|
|
||||||
categories: [videos]
|
|
||||||
chinaso_category: videos
|
|
||||||
|
|
||||||
|
|
||||||
Implementations
|
Implementations
|
||||||
===============
|
===============
|
||||||
@@ -78,19 +61,6 @@ results_per_page = 10
|
|||||||
categories = []
|
categories = []
|
||||||
language = "zh"
|
language = "zh"
|
||||||
|
|
||||||
ChinasoCategoryType = t.Literal['news', 'videos', 'images']
|
|
||||||
"""ChinaSo supports news, videos, images search.
|
|
||||||
|
|
||||||
- ``news``: search for news
|
|
||||||
- ``videos``: search for videos
|
|
||||||
- ``images``: search for images
|
|
||||||
|
|
||||||
In the category ``news`` you can additionally filter by option
|
|
||||||
:py:obj:`chinaso_news_source`.
|
|
||||||
"""
|
|
||||||
chinaso_category = 'news'
|
|
||||||
"""Configure ChinaSo category (:py:obj:`ChinasoCategoryType`)."""
|
|
||||||
|
|
||||||
ChinasoNewsSourceType = t.Literal['CENTRAL', 'LOCAL', 'BUSINESS', 'EPAPER', 'all']
|
ChinasoNewsSourceType = t.Literal['CENTRAL', 'LOCAL', 'BUSINESS', 'EPAPER', 'all']
|
||||||
"""Filtering ChinaSo-News results by source:
|
"""Filtering ChinaSo-News results by source:
|
||||||
|
|
||||||
@@ -109,39 +79,24 @@ base_url = "https://www.chinaso.com"
|
|||||||
|
|
||||||
|
|
||||||
def init(_):
|
def init(_):
|
||||||
if chinaso_category not in ('news', 'videos', 'images'):
|
if chinaso_news_source not in t.get_args(ChinasoNewsSourceType):
|
||||||
raise ValueError(f"Unsupported category: {chinaso_category}")
|
|
||||||
if chinaso_category == 'news' and chinaso_news_source not in t.get_args(ChinasoNewsSourceType):
|
|
||||||
raise ValueError(f"Unsupported news source: {chinaso_news_source}")
|
raise ValueError(f"Unsupported news source: {chinaso_news_source}")
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
query_params = {"q": query}
|
query_params = {'q': query, 'pn': params["pageno"], 'ps': results_per_page}
|
||||||
|
|
||||||
if time_range_dict.get(params['time_range']):
|
if time_range_dict.get(params['time_range']):
|
||||||
query_params["stime"] = time_range_dict[params['time_range']]
|
query_params["stime"] = time_range_dict[params['time_range']]
|
||||||
query_params["etime"] = 'now'
|
query_params["etime"] = 'now'
|
||||||
|
|
||||||
category_config = {
|
|
||||||
'news': {'endpoint': '/v5/general/v1/web/search', 'params': {'pn': params["pageno"], 'ps': results_per_page}},
|
|
||||||
'images': {
|
|
||||||
'endpoint': '/v5/general/v1/search/image',
|
|
||||||
'params': {'start_index': (params["pageno"] - 1) * results_per_page, 'rn': results_per_page},
|
|
||||||
},
|
|
||||||
'videos': {
|
|
||||||
'endpoint': '/v5/general/v1/search/video',
|
|
||||||
'params': {'start_index': (params["pageno"] - 1) * results_per_page, 'rn': results_per_page},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if chinaso_news_source != 'all':
|
if chinaso_news_source != 'all':
|
||||||
if chinaso_news_source == 'EPAPER':
|
if chinaso_news_source == 'EPAPER':
|
||||||
category_config['news']['params']["type"] = 'EPAPER'
|
query_params["type"] = 'EPAPER'
|
||||||
else:
|
else:
|
||||||
category_config['news']['params']["cate"] = chinaso_news_source
|
query_params["cate"] = chinaso_news_source
|
||||||
|
|
||||||
query_params.update(category_config[chinaso_category]['params'])
|
params["url"] = f"{base_url}/v5/general/v1/web/search?{urlencode(query_params)}"
|
||||||
|
|
||||||
params["url"] = f"{base_url}{category_config[chinaso_category]['endpoint']}?{urlencode(query_params)}"
|
|
||||||
cookie = {
|
cookie = {
|
||||||
"uid": base64.b64encode(secrets.token_bytes(16)).decode("utf-8"),
|
"uid": base64.b64encode(secrets.token_bytes(16)).decode("utf-8"),
|
||||||
}
|
}
|
||||||
@@ -163,12 +118,6 @@ def response(resp):
|
|||||||
if not data["data"]:
|
if not data["data"]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
parsers = {'news': parse_news, 'images': parse_images, 'videos': parse_videos}
|
|
||||||
|
|
||||||
return parsers[chinaso_category](data)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_news(data):
|
|
||||||
results = []
|
results = []
|
||||||
if not data.get("data", {}).get("data"):
|
if not data.get("data", {}).get("data"):
|
||||||
raise SearxEngineAPIException("Invalid response")
|
raise SearxEngineAPIException("Invalid response")
|
||||||
@@ -190,47 +139,3 @@ def parse_news(data):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def parse_images(data):
|
|
||||||
results = []
|
|
||||||
if not data.get("data", {}).get("arrRes"):
|
|
||||||
raise SearxEngineAPIException("Invalid response")
|
|
||||||
|
|
||||||
for entry in data["data"]["arrRes"]:
|
|
||||||
results.append(
|
|
||||||
{
|
|
||||||
'url': entry["web_url"],
|
|
||||||
'title': html_to_text(entry["title"]),
|
|
||||||
'content': html_to_text(entry.get("ImageInfo", "")),
|
|
||||||
'template': 'images.html',
|
|
||||||
'img_src': entry["url"].replace("http://", "https://"),
|
|
||||||
'thumbnail_src': entry["largeimage"].replace("http://", "https://"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def parse_videos(data):
|
|
||||||
results = []
|
|
||||||
if not data.get("data", {}).get("arrRes"):
|
|
||||||
raise SearxEngineAPIException("Invalid response")
|
|
||||||
|
|
||||||
for entry in data["data"]["arrRes"]:
|
|
||||||
published_date = None
|
|
||||||
if entry.get("VideoPubDate"):
|
|
||||||
try:
|
|
||||||
published_date = datetime.fromtimestamp(int(entry["VideoPubDate"]))
|
|
||||||
except (ValueError, TypeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
results.append(
|
|
||||||
{
|
|
||||||
'url': entry["url"],
|
|
||||||
'title': html_to_text(entry["raw_title"]),
|
|
||||||
'template': 'videos.html',
|
|
||||||
'publishedDate': published_date,
|
|
||||||
'thumbnail': entry["image_src"].replace("http://", "https://"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return results
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ def _image_results(doc: "ElementBase") -> EngineResults:
|
|||||||
res.types.Image(
|
res.types.Image(
|
||||||
url=extract_text(eval_xpath(result, "./@href")) or "",
|
url=extract_text(eval_xpath(result, "./@href")) or "",
|
||||||
title=extract_text(eval_xpath(result, "./img/@alt")) or "",
|
title=extract_text(eval_xpath(result, "./img/@alt")) or "",
|
||||||
thumbnail_src=extract_text(eval_xpath(result, "./img/@src")) or "",
|
img_src=extract_text(eval_xpath(result, "./img/@src")) or "",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ def _obtain_session_code() -> str:
|
|||||||
if cached_session:
|
if cached_session:
|
||||||
return cached_session
|
return cached_session
|
||||||
|
|
||||||
results_page = get(f"{base_url}/_internCode.aspx")
|
results_page = get(f"{base_url}/checkCode.aspx")
|
||||||
doc = html.fromstring(results_page.text)
|
doc = html.fromstring(results_page.text)
|
||||||
|
|
||||||
extra_data: dict[str, str] = {}
|
extra_data: dict[str, str] = {}
|
||||||
@@ -107,7 +107,7 @@ def _obtain_session_code() -> str:
|
|||||||
}
|
}
|
||||||
|
|
||||||
challenge_response = post(
|
challenge_response = post(
|
||||||
f"{base_url}/_internCode.aspx",
|
f"{base_url}/checkCode.aspx",
|
||||||
cookies=results_page.cookies,
|
cookies=results_page.cookies,
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -125,7 +125,9 @@ def request(query: str, params: "OnlineParams"):
|
|||||||
code = _obtain_session_code()
|
code = _obtain_session_code()
|
||||||
args = {"w": query, "page": params["pageno"]}
|
args = {"w": query, "page": params["pageno"]}
|
||||||
params["url"] = f"{base_url}/{tiger_category}?{urlencode(args)}"
|
params["url"] = f"{base_url}/{tiger_category}?{urlencode(args)}"
|
||||||
params["cookies"]["Tiger.ch"] = f"Code={code}"
|
# Setting Checked=1 shows related search terms / suggestions
|
||||||
|
# Language and country could be set with Lng= and Land= in the future
|
||||||
|
params["cookies"]["Tiger.ch"] = f"Tiger.ch=&Code={code}&Checked=1"
|
||||||
|
|
||||||
|
|
||||||
def response(resp: "SXNG_Response") -> EngineResults:
|
def response(resp: "SXNG_Response") -> EngineResults:
|
||||||
@@ -144,6 +146,9 @@ def response(resp: "SXNG_Response") -> EngineResults:
|
|||||||
content=extract_text(eval_xpath(result, ".//*[contains(@class, 'webbodynopic')]")) or "",
|
content=extract_text(eval_xpath(result, ".//*[contains(@class, 'webbodynopic')]")) or "",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for suggestion in eval_xpath_list(doc, "//a[contains(@class, 'linkAnders')]"):
|
||||||
|
res.add(res.types.LegacyResult(suggestion=extract_text(suggestion)))
|
||||||
elif tiger_category == "News":
|
elif tiger_category == "News":
|
||||||
for result in eval_xpath_list(doc, "//div[@id='panNews']/div"):
|
for result in eval_xpath_list(doc, "//div[@id='panNews']/div"):
|
||||||
publishedDate = None
|
publishedDate = None
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ template.
|
|||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
__all__ = ["Image", "ImageRef"]
|
__all__ = ["Image", "ImageRef"]
|
||||||
|
|
||||||
|
import mimetypes
|
||||||
import types
|
import types
|
||||||
import typing as t
|
import typing as t
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
@@ -71,7 +72,7 @@ class Image(MainResult, kw_only=True):
|
|||||||
"""The resolution of the image (e.g. ``1920 x 1080`` pixel)"""
|
"""The resolution of the image (e.g. ``1920 x 1080`` pixel)"""
|
||||||
|
|
||||||
img_format: str = ""
|
img_format: str = ""
|
||||||
"""The format of the image (e.g. ``png``)."""
|
"""The format of the image :py:obj:`.MainResult.img_src` (e.g. ``png``)."""
|
||||||
|
|
||||||
source: str = ""
|
source: str = ""
|
||||||
"""Source of the image."""
|
"""Source of the image."""
|
||||||
@@ -83,6 +84,19 @@ class Image(MainResult, kw_only=True):
|
|||||||
formats: list[ImageRef] = []
|
formats: list[ImageRef] = []
|
||||||
"""List of links to alternative image formats."""
|
"""List of links to alternative image formats."""
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
super().__post_init__()
|
||||||
|
|
||||||
|
if not self.img_format:
|
||||||
|
# automatically guess the image format based on the path of the image
|
||||||
|
mimetype = mimetypes.guess_type(self.img_src)[0]
|
||||||
|
if mimetype:
|
||||||
|
subtype = mimetype.split("/")[-1]
|
||||||
|
if subtype in MIMESUB:
|
||||||
|
self.img_format = MIMESUB[subtype]
|
||||||
|
else:
|
||||||
|
self.img_format = subtype.upper()
|
||||||
|
|
||||||
def filter_urls(self, filter_func: "Callable[[Result | LegacyResult, str, str], str | bool ]"):
|
def filter_urls(self, filter_func: "Callable[[Result | LegacyResult, str, str], str | bool ]"):
|
||||||
|
|
||||||
for _ref in self.formats[:]:
|
for _ref in self.formats[:]:
|
||||||
|
|||||||
@@ -443,6 +443,12 @@ engines:
|
|||||||
timeout: 6.0
|
timeout: 6.0
|
||||||
shortcut: conda
|
shortcut: conda
|
||||||
disabled: true
|
disabled: true
|
||||||
|
about:
|
||||||
|
website: https://anaconda.org/search
|
||||||
|
wikidata_id: Q18209310
|
||||||
|
official_api_documentation: https://api.anaconda.org/search
|
||||||
|
use_official_api: false
|
||||||
|
results: HTML
|
||||||
|
|
||||||
- name: arch linux wiki
|
- name: arch linux wiki
|
||||||
engine: archlinux
|
engine: archlinux
|
||||||
@@ -644,29 +650,10 @@ engines:
|
|||||||
engine: chinaso
|
engine: chinaso
|
||||||
shortcut: chinaso
|
shortcut: chinaso
|
||||||
categories: [news]
|
categories: [news]
|
||||||
chinaso_category: news
|
|
||||||
chinaso_news_source: all
|
chinaso_news_source: all
|
||||||
disabled: true
|
disabled: true
|
||||||
inactive: true
|
inactive: true
|
||||||
|
|
||||||
- name: chinaso images
|
|
||||||
engine: chinaso
|
|
||||||
network: chinaso news
|
|
||||||
shortcut: chinasoi
|
|
||||||
categories: [images]
|
|
||||||
chinaso_category: images
|
|
||||||
disabled: true
|
|
||||||
inactive: true
|
|
||||||
|
|
||||||
- name: chinaso videos
|
|
||||||
engine: chinaso
|
|
||||||
network: chinaso news
|
|
||||||
shortcut: chinasov
|
|
||||||
categories: [videos]
|
|
||||||
chinaso_category: videos
|
|
||||||
disabled: true
|
|
||||||
inactive: true
|
|
||||||
|
|
||||||
- name: cl0q
|
- name: cl0q
|
||||||
engine: json_engine
|
engine: json_engine
|
||||||
shortcut: cl
|
shortcut: cl
|
||||||
@@ -1424,12 +1411,10 @@ engines:
|
|||||||
|
|
||||||
- name: kozmonavt
|
- name: kozmonavt
|
||||||
engine: xpath
|
engine: xpath
|
||||||
paging: true
|
search_url: https://kozmonavt.su/s?q={query}
|
||||||
# pageno query param key is U+1D5D1 (looks like an "x")
|
|
||||||
search_url: https://kozmonavt.su/s?q={query}&%F0%9D%97%91={pageno}
|
|
||||||
shortcut: koz
|
shortcut: koz
|
||||||
disabled: true
|
disabled: true
|
||||||
# inactive: true
|
inactive: true
|
||||||
results_xpath: //div[contains(@class, 'list')]/section
|
results_xpath: //div[contains(@class, 'list')]/section
|
||||||
url_xpath: concat('https://', substring-after(.//a/@href, '?q='))
|
url_xpath: concat('https://', substring-after(.//a/@href, '?q='))
|
||||||
title_xpath: .//a
|
title_xpath: .//a
|
||||||
|
|||||||
Binary file not shown.
@@ -33,22 +33,24 @@
|
|||||||
# IcewindX <icewindx@noreply.codeberg.org>, 2025.
|
# IcewindX <icewindx@noreply.codeberg.org>, 2025.
|
||||||
# 0ko <0ko@noreply.codeberg.org>, 2025.
|
# 0ko <0ko@noreply.codeberg.org>, 2025.
|
||||||
# greatdng <greatdng@noreply.codeberg.org>, 2026.
|
# greatdng <greatdng@noreply.codeberg.org>, 2026.
|
||||||
|
# code_gremlin <code_gremlin@noreply.codeberg.org>, 2026.
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: searx\n"
|
"Project-Id-Version: searx\n"
|
||||||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
|
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
|
||||||
"POT-Creation-Date: 2026-06-13 11:31+0000\n"
|
"POT-Creation-Date: 2026-06-13 11:31+0000\n"
|
||||||
"PO-Revision-Date: 2026-05-19 12:08+0000\n"
|
"PO-Revision-Date: 2026-06-24 10:07+0000\n"
|
||||||
"Last-Translator: return42 <return42@noreply.codeberg.org>\n"
|
"Last-Translator: code_gremlin <code_gremlin@noreply.codeberg.org>\n"
|
||||||
|
"Language-Team: Russian <https://translate.codeberg.org/projects/searxng/"
|
||||||
|
"searxng/ru/>\n"
|
||||||
"Language: ru\n"
|
"Language: ru\n"
|
||||||
"Language-Team: Russian "
|
|
||||||
"<https://translate.codeberg.org/projects/searxng/searxng/ru/>\n"
|
|
||||||
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
|
|
||||||
"n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) "
|
|
||||||
"|| (n%100>=11 && n%100<=14)? 2 : 3);\n"
|
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=utf-8\n"
|
"Content-Type: text/plain; charset=utf-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
|
||||||
|
"n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || "
|
||||||
|
"(n%100>=11 && n%100<=14)? 2 : 3);\n"
|
||||||
|
"X-Generator: Weblate 2026.6.1\n"
|
||||||
"Generated-By: Babel 2.18.0\n"
|
"Generated-By: Babel 2.18.0\n"
|
||||||
|
|
||||||
#. CONSTANT_NAMES['NO_SUBGROUPING']
|
#. CONSTANT_NAMES['NO_SUBGROUPING']
|
||||||
@@ -1667,11 +1669,11 @@ msgstr "Разрешение"
|
|||||||
|
|
||||||
#: searx/templates/simple/result_templates/images.html:55
|
#: searx/templates/simple/result_templates/images.html:55
|
||||||
msgid "Image formats"
|
msgid "Image formats"
|
||||||
msgstr ""
|
msgstr "Форматы изображений"
|
||||||
|
|
||||||
#: searx/templates/simple/result_templates/images.html:56
|
#: searx/templates/simple/result_templates/images.html:56
|
||||||
msgid "original format"
|
msgid "original format"
|
||||||
msgstr ""
|
msgstr "формат оригинала"
|
||||||
|
|
||||||
#: searx/templates/simple/result_templates/images.html:63
|
#: searx/templates/simple/result_templates/images.html:63
|
||||||
msgid "Engine"
|
msgid "Engine"
|
||||||
@@ -2441,4 +2443,3 @@ msgstr "скрыть видео"
|
|||||||
|
|
||||||
#~ msgid "Format"
|
#~ msgid "Format"
|
||||||
#~ msgstr "Формат"
|
#~ msgstr "Формат"
|
||||||
|
|
||||||
|
|||||||
@@ -15,25 +15,26 @@ from os.path import join
|
|||||||
|
|
||||||
from lxml.html import fromstring
|
from lxml.html import fromstring
|
||||||
|
|
||||||
|
import searx.engines
|
||||||
from searx.engines import wikidata, set_loggers
|
from searx.engines import wikidata, set_loggers
|
||||||
from searx.utils import extract_text, searxng_useragent
|
from searx.utils import extract_text
|
||||||
from searx.locales import LOCALE_NAMES, locales_initialize, match_locale
|
from searx.locales import LOCALE_NAMES, locales_initialize, match_locale
|
||||||
from searx import searx_dir
|
from searx import searx_dir
|
||||||
from searx.utils import gen_useragent
|
from searx.utils import gen_useragent
|
||||||
import searx.search
|
import searx.search
|
||||||
import searx.network
|
import searx.network
|
||||||
from searx.data import data_dir
|
from searx.data import data_dir, ENGINE_DESCRIPTIONS
|
||||||
|
|
||||||
DATA_FILE = data_dir / 'engine_descriptions.json'
|
DATA_FILE = data_dir / "engine_descriptions.json"
|
||||||
|
|
||||||
set_loggers(wikidata, 'wikidata')
|
set_loggers(wikidata, "wikidata")
|
||||||
locales_initialize()
|
locales_initialize()
|
||||||
|
|
||||||
# you can run the query in https://query.wikidata.org
|
# you can run the query in https://query.wikidata.org
|
||||||
# replace %IDS% by Wikidata entities separated by spaces with the prefix wd:
|
# replace %IDS% by Wikidata entities separated by spaces with the prefix wd:
|
||||||
# for example wd:Q182496 wd:Q1540899
|
# for example wd:Q182496 wd:Q1540899
|
||||||
# replace %LANGUAGES_SPARQL% by languages
|
# replace %LANGUAGES_SPARQL% by languages
|
||||||
SPARQL_WIKIPEDIA_ARTICLE = """
|
SPARQL_WIKIPEDIA_ARTICLE: str = """
|
||||||
SELECT DISTINCT ?item ?name ?article ?lang
|
SELECT DISTINCT ?item ?name ?article ?lang
|
||||||
WHERE {
|
WHERE {
|
||||||
hint:Query hint:optimizer "None".
|
hint:Query hint:optimizer "None".
|
||||||
@@ -48,7 +49,7 @@ WHERE {
|
|||||||
ORDER BY ?item ?lang
|
ORDER BY ?item ?lang
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SPARQL_DESCRIPTION = """
|
SPARQL_DESCRIPTION: str = """
|
||||||
SELECT DISTINCT ?item ?itemDescription
|
SELECT DISTINCT ?item ?itemDescription
|
||||||
WHERE {
|
WHERE {
|
||||||
VALUES ?item { %IDS% }
|
VALUES ?item { %IDS% }
|
||||||
@@ -58,43 +59,43 @@ WHERE {
|
|||||||
ORDER BY ?itemLang
|
ORDER BY ?itemLang
|
||||||
"""
|
"""
|
||||||
|
|
||||||
NOT_A_DESCRIPTION = [
|
NOT_A_DESCRIPTION: list[str] = [
|
||||||
'web site',
|
"web site",
|
||||||
'site web',
|
"site web",
|
||||||
'komputa serĉilo',
|
"komputa serĉilo",
|
||||||
'interreta serĉilo',
|
"interreta serĉilo",
|
||||||
'bilaketa motor',
|
"bilaketa motor",
|
||||||
'web search engine',
|
"web search engine",
|
||||||
'wikimedia täpsustuslehekülg',
|
"wikimedia täpsustuslehekülg",
|
||||||
]
|
]
|
||||||
|
|
||||||
SKIP_ENGINE_SOURCE = [
|
SKIP_ENGINE_SOURCE: list[tuple[str, str]] = [
|
||||||
# fmt: off
|
# fmt: off
|
||||||
('gitlab', 'wikidata')
|
("gitlab", "wikidata")
|
||||||
# descriptions are about wikipedia disambiguation pages
|
# descriptions are about wikipedia disambiguation pages
|
||||||
# fmt: on
|
# fmt: on
|
||||||
]
|
]
|
||||||
|
|
||||||
WIKIPEDIA_LANGUAGES = {}
|
WIKIPEDIA_LANGUAGES: dict[str, str] = {}
|
||||||
LANGUAGES_SPARQL = ''
|
LANGUAGES_SPARQL: str = ""
|
||||||
IDS = None
|
IDS: str = ""
|
||||||
WIKIPEDIA_LANGUAGE_VARIANTS = {'zh_Hant': 'zh-tw'}
|
WIKIPEDIA_LANGUAGE_VARIANTS: dict[str, str] = {"zh_Hant": "zh-tw"}
|
||||||
|
|
||||||
|
# descriptions[engine][language] = [description, source]
|
||||||
|
descriptions: dict[str, dict[str, list[str]]] = {}
|
||||||
|
wd_to_engine_name: dict[str, set[str]] = {}
|
||||||
|
|
||||||
|
|
||||||
descriptions = {}
|
def normalize_description(description: str):
|
||||||
wd_to_engine_name = {}
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_description(description):
|
|
||||||
for c in [chr(c) for c in range(0, 31)]:
|
for c in [chr(c) for c in range(0, 31)]:
|
||||||
description = description.replace(c, ' ')
|
description = description.replace(c, " ")
|
||||||
description = ' '.join(description.strip().split())
|
description = " ".join(description.strip().split())
|
||||||
return description
|
return description
|
||||||
|
|
||||||
|
|
||||||
def update_description(engine_name, lang, description, source, replace=True):
|
def update_description(engine_name: str, lang: str, description: str, source: str, replace: bool = True) -> None:
|
||||||
if not isinstance(description, str):
|
if not isinstance(description, str):
|
||||||
return
|
return # pyright: ignore[reportUnreachable]
|
||||||
description = normalize_description(description)
|
description = normalize_description(description)
|
||||||
if description.lower() == engine_name.lower():
|
if description.lower() == engine_name.lower():
|
||||||
return
|
return
|
||||||
@@ -102,54 +103,71 @@ def update_description(engine_name, lang, description, source, replace=True):
|
|||||||
return
|
return
|
||||||
if (engine_name, source) in SKIP_ENGINE_SOURCE:
|
if (engine_name, source) in SKIP_ENGINE_SOURCE:
|
||||||
return
|
return
|
||||||
if ' ' not in description:
|
if " " not in description:
|
||||||
# skip unique word description (like "website")
|
# skip unique word description (like "website")
|
||||||
return
|
return
|
||||||
if replace or lang not in descriptions[engine_name]:
|
if replace or lang not in descriptions[engine_name]:
|
||||||
descriptions[engine_name][lang] = [description, source]
|
descriptions[engine_name][lang] = [description, source]
|
||||||
|
|
||||||
|
|
||||||
def get_wikipedia_summary(wikipedia_url, searxng_locale):
|
def get_wikipedia_summary(wikipedia_url: str, searxng_locale: str):
|
||||||
# get the REST API URL from the HTML URL
|
# get the REST API URL from the HTML URL
|
||||||
|
|
||||||
# Headers
|
# Headers
|
||||||
headers = {'User-Agent': searxng_useragent()}
|
headers = {
|
||||||
|
"User-Agent": gen_useragent(),
|
||||||
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
||||||
|
"Accept-Encoding": "gzip, deflate",
|
||||||
|
"DNT": "1",
|
||||||
|
"Upgrade-Insecure-Requests": "1",
|
||||||
|
"Sec-GPC": "1",
|
||||||
|
"Cache-Control": "max-age=0",
|
||||||
|
"Sec-Fetch-Dest": "document",
|
||||||
|
"Sec-Fetch-Mode": "navigate",
|
||||||
|
"Sec-Fetch-Site": "same-origin",
|
||||||
|
"Sec-Fetch-User": "?1",
|
||||||
|
}
|
||||||
|
|
||||||
if searxng_locale in WIKIPEDIA_LANGUAGE_VARIANTS:
|
if searxng_locale in WIKIPEDIA_LANGUAGE_VARIANTS:
|
||||||
headers['Accept-Language'] = WIKIPEDIA_LANGUAGE_VARIANTS.get(searxng_locale)
|
headers["Accept-Language"] = WIKIPEDIA_LANGUAGE_VARIANTS[searxng_locale]
|
||||||
|
|
||||||
# URL path : from HTML URL to REST API URL
|
# URL path : from HTML URL to REST API URL
|
||||||
parsed_url = urlparse(wikipedia_url)
|
parsed_url = urlparse(wikipedia_url)
|
||||||
# remove the /wiki/ prefix
|
# remove the /wiki/ prefix
|
||||||
article_name = parsed_url.path.split('/wiki/')[1]
|
article_name = parsed_url.path.split("/wiki/")[1]
|
||||||
# article_name is already encoded but not the / which is required for the REST API call
|
# article_name is already encoded but not the / which is required for the REST API call
|
||||||
encoded_article_name = article_name.replace('/', '%2F')
|
encoded_article_name = article_name.replace("/", "%2F")
|
||||||
path = '/api/rest_v1/page/summary/' + encoded_article_name
|
path = "/api/rest_v1/page/summary/" + encoded_article_name
|
||||||
wikipedia_rest_url = parsed_url._replace(path=path).geturl()
|
wikipedia_rest_url = parsed_url._replace(path=path).geturl()
|
||||||
try:
|
try:
|
||||||
response = searx.network.get(wikipedia_rest_url, headers=headers, timeout=10)
|
response = searx.network.get(wikipedia_rest_url, headers=headers, timeout=10)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as e: # pylint: disable=broad-except
|
except Exception as e: # pylint: disable=broad-except
|
||||||
print(" ", wikipedia_url, e)
|
print(" get_wikipedia_summary: ", wikipedia_rest_url, e)
|
||||||
return None
|
return None
|
||||||
api_result = json.loads(response.text)
|
api_result = json.loads(response.text)
|
||||||
return api_result.get('extract')
|
return api_result.get("extract")
|
||||||
|
|
||||||
|
|
||||||
def get_website_description(url, lang1, lang2=None):
|
def get_website_description(url: str, lang1: str | None, lang2: str | None = None):
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': gen_useragent(),
|
"User-Agent": gen_useragent(),
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
||||||
'DNT': '1',
|
"Accept-Encoding": "gzip, deflate",
|
||||||
'Upgrade-Insecure-Requests': '1',
|
"DNT": "1",
|
||||||
'Sec-GPC': '1',
|
"Upgrade-Insecure-Requests": "1",
|
||||||
'Cache-Control': 'max-age=0',
|
"Sec-GPC": "1",
|
||||||
|
"Cache-Control": "max-age=0",
|
||||||
|
"Sec-Fetch-Dest": "document",
|
||||||
|
"Sec-Fetch-Mode": "navigate",
|
||||||
|
"Sec-Fetch-Site": "same-origin",
|
||||||
|
"Sec-Fetch-User": "?1",
|
||||||
}
|
}
|
||||||
if lang1 is not None:
|
if lang1 is not None:
|
||||||
lang_list = [lang1]
|
lang_list = [lang1]
|
||||||
if lang2 is not None:
|
if lang2 is not None:
|
||||||
lang_list.append(lang2)
|
lang_list.append(lang2)
|
||||||
headers['Accept-Language'] = f'{",".join(lang_list)};q=0.8'
|
headers["Accept-Language"] = f'{",".join(lang_list)};q=0.8'
|
||||||
try:
|
try:
|
||||||
response = searx.network.get(url, headers=headers, timeout=10)
|
response = searx.network.get(url, headers=headers, timeout=10)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@@ -167,7 +185,7 @@ def get_website_description(url, lang1, lang2=None):
|
|||||||
if not description:
|
if not description:
|
||||||
description = extract_text(html.xpath('/html/head/title'))
|
description = extract_text(html.xpath('/html/head/title'))
|
||||||
lang = extract_text(html.xpath('/html/@lang'))
|
lang = extract_text(html.xpath('/html/@lang'))
|
||||||
if lang is None and len(lang1) > 0:
|
if lang is None and lang1 and len(lang1) > 0:
|
||||||
lang = lang1
|
lang = lang1
|
||||||
lang = lang or 'en'
|
lang = lang or 'en'
|
||||||
lang = lang.split('_')[0]
|
lang = lang.split('_')[0]
|
||||||
@@ -178,15 +196,15 @@ def get_website_description(url, lang1, lang2=None):
|
|||||||
def initialize():
|
def initialize():
|
||||||
global IDS, LANGUAGES_SPARQL
|
global IDS, LANGUAGES_SPARQL
|
||||||
searx.search.initialize()
|
searx.search.initialize()
|
||||||
wikipedia_engine = searx.engines.engines['wikipedia']
|
wikipedia_engine = searx.engines.engines["wikipedia"]
|
||||||
|
|
||||||
locale2lang = {'nl-BE': 'nl'}
|
locale2lang = {"nl-BE": "nl"}
|
||||||
for sxng_ui_lang in LOCALE_NAMES:
|
for sxng_ui_lang in LOCALE_NAMES:
|
||||||
|
|
||||||
sxng_ui_alias = locale2lang.get(sxng_ui_lang, sxng_ui_lang)
|
sxng_ui_alias = locale2lang.get(sxng_ui_lang, sxng_ui_lang)
|
||||||
wiki_lang = None
|
wiki_lang = None
|
||||||
|
|
||||||
if sxng_ui_alias in wikipedia_engine.traits.custom['WIKIPEDIA_LANGUAGES']:
|
if sxng_ui_alias in wikipedia_engine.traits.custom["WIKIPEDIA_LANGUAGES"]:
|
||||||
wiki_lang = sxng_ui_alias
|
wiki_lang = sxng_ui_alias
|
||||||
if not wiki_lang:
|
if not wiki_lang:
|
||||||
wiki_lang = wikipedia_engine.traits.get_language(sxng_ui_alias)
|
wiki_lang = wikipedia_engine.traits.get_language(sxng_ui_alias)
|
||||||
@@ -195,27 +213,29 @@ def initialize():
|
|||||||
continue
|
continue
|
||||||
WIKIPEDIA_LANGUAGES[sxng_ui_lang] = wiki_lang
|
WIKIPEDIA_LANGUAGES[sxng_ui_lang] = wiki_lang
|
||||||
|
|
||||||
LANGUAGES_SPARQL = ', '.join(f"'{l}'" for l in set(WIKIPEDIA_LANGUAGES.values()))
|
LANGUAGES_SPARQL = ", ".join(f"'{l}'" for l in set(WIKIPEDIA_LANGUAGES.values()))
|
||||||
for engine_name, engine in searx.engines.engines.items():
|
for engine_name, engine in searx.engines.engines.items():
|
||||||
descriptions[engine_name] = {}
|
descriptions[engine_name] = {}
|
||||||
wikidata_id = getattr(engine, "about", {}).get('wikidata_id')
|
if engine.about.wikidata_id:
|
||||||
if wikidata_id is not None:
|
wd_to_engine_name.setdefault(engine.about.wikidata_id, set()).add(engine_name)
|
||||||
wd_to_engine_name.setdefault(wikidata_id, set()).add(engine_name)
|
|
||||||
|
|
||||||
IDS = ' '.join(list(map(lambda wd_id: 'wd:' + wd_id, wd_to_engine_name.keys())))
|
IDS = " ".join(list(map(lambda wd_id: "wd:" + wd_id, wd_to_engine_name.keys())))
|
||||||
|
|
||||||
|
|
||||||
def fetch_wikidata_descriptions():
|
def fetch_wikidata_descriptions():
|
||||||
print('Fetching wikidata descriptions')
|
print("Fetching wikidata descriptions")
|
||||||
searx.network.set_timeout_for_thread(60)
|
searx.network.set_timeout_for_thread(60)
|
||||||
result = wikidata.send_wikidata_query(
|
result = wikidata.send_wikidata_query(
|
||||||
SPARQL_DESCRIPTION.replace('%IDS%', IDS).replace('%LANGUAGES_SPARQL%', LANGUAGES_SPARQL)
|
SPARQL_DESCRIPTION.replace("%IDS%", IDS).replace("%LANGUAGES_SPARQL%", LANGUAGES_SPARQL)
|
||||||
)
|
)
|
||||||
if result is not None:
|
if not result:
|
||||||
for binding in result['results']['bindings']:
|
print("ERROR: fetching wikiDATA descriptions - SPARQL_DESCRIPTION query without results.")
|
||||||
wikidata_id = binding['item']['value'].replace('http://www.wikidata.org/entity/', '')
|
return
|
||||||
wikidata_lang = binding['itemDescription']['xml:lang']
|
|
||||||
desc = binding['itemDescription']['value']
|
for binding in result["results"]["bindings"]:
|
||||||
|
wikidata_id = binding["item"]["value"].replace("http://www.wikidata.org/entity/", "")
|
||||||
|
wikidata_lang = binding["itemDescription"]["xml:lang"]
|
||||||
|
desc = binding["itemDescription"]["value"]
|
||||||
for engine_name in wd_to_engine_name[wikidata_id]:
|
for engine_name in wd_to_engine_name[wikidata_id]:
|
||||||
for searxng_locale in LOCALE_NAMES:
|
for searxng_locale in LOCALE_NAMES:
|
||||||
if WIKIPEDIA_LANGUAGES[searxng_locale] != wikidata_lang:
|
if WIKIPEDIA_LANGUAGES[searxng_locale] != wikidata_lang:
|
||||||
@@ -224,41 +244,53 @@ def fetch_wikidata_descriptions():
|
|||||||
f" engine: {engine_name:20} / wikidata_lang: {wikidata_lang:5}",
|
f" engine: {engine_name:20} / wikidata_lang: {wikidata_lang:5}",
|
||||||
f"/ len(wikidata_desc): {len(desc)}",
|
f"/ len(wikidata_desc): {len(desc)}",
|
||||||
)
|
)
|
||||||
update_description(engine_name, searxng_locale, desc, 'wikidata')
|
update_description(engine_name, searxng_locale, desc, "wikidata")
|
||||||
|
|
||||||
|
|
||||||
def fetch_wikipedia_descriptions():
|
def fetch_wikipedia_descriptions():
|
||||||
print('Fetching wikipedia descriptions')
|
print("Fetching wikipedia descriptions")
|
||||||
result = wikidata.send_wikidata_query(
|
result = wikidata.send_wikidata_query(
|
||||||
SPARQL_WIKIPEDIA_ARTICLE.replace('%IDS%', IDS).replace('%LANGUAGES_SPARQL%', LANGUAGES_SPARQL)
|
SPARQL_WIKIPEDIA_ARTICLE.replace("%IDS%", IDS).replace("%LANGUAGES_SPARQL%", LANGUAGES_SPARQL)
|
||||||
)
|
)
|
||||||
if result is not None:
|
if not result:
|
||||||
for binding in result['results']['bindings']:
|
print("ERROR: fetching wikiPEDIA descriptions - SPARQL_WIKIPEDIA_ARTICLE query without results.")
|
||||||
wikidata_id = binding['item']['value'].replace('http://www.wikidata.org/entity/', '')
|
return
|
||||||
wikidata_lang = binding['name']['xml:lang']
|
|
||||||
wikipedia_url = binding['article']['value'] # for example the URL https://de.wikipedia.org/wiki/PubMed
|
# pylint: disable=too-many-nested-blocks
|
||||||
|
for binding in result["results"]["bindings"]:
|
||||||
|
wikidata_id = binding["item"]["value"].replace("http://www.wikidata.org/entity/", "")
|
||||||
|
wikidata_lang = binding["name"]["xml:lang"]
|
||||||
|
wikipedia_url = binding["article"]["value"] # for example the URL https://de.wikipedia.org/wiki/PubMed
|
||||||
for engine_name in wd_to_engine_name[wikidata_id]:
|
for engine_name in wd_to_engine_name[wikidata_id]:
|
||||||
for searxng_locale in LOCALE_NAMES:
|
for searxng_locale in LOCALE_NAMES:
|
||||||
if WIKIPEDIA_LANGUAGES[searxng_locale] != wikidata_lang:
|
if WIKIPEDIA_LANGUAGES[searxng_locale] != wikidata_lang:
|
||||||
continue
|
continue
|
||||||
desc = get_wikipedia_summary(wikipedia_url, searxng_locale)
|
desc = get_wikipedia_summary(wikipedia_url, searxng_locale)
|
||||||
if not desc:
|
if not desc:
|
||||||
|
if descriptions.get(searxng_locale, {}).get(engine_name) is None:
|
||||||
|
_descr = ENGINE_DESCRIPTIONS.get(searxng_locale, {}).get(engine_name)
|
||||||
|
if _descr is not None:
|
||||||
|
if len(_descr) == 2 and _descr[1] == 'ref':
|
||||||
|
ref_engine, ref_lang = _descr[0].split(':')
|
||||||
|
_descr = ENGINE_DESCRIPTIONS[ref_lang][ref_engine]
|
||||||
|
update_description(engine_name, searxng_locale, _descr[0], _descr[1])
|
||||||
|
|
||||||
continue
|
continue
|
||||||
print(
|
print(
|
||||||
f" engine: {engine_name:20} / wikidata_lang: {wikidata_lang:5}",
|
f" engine: {engine_name:20} / wikidata_lang: {wikidata_lang:5}",
|
||||||
f"/ len(wikipedia_desc): {len(desc)}",
|
f"/ len(wikipedia_desc): {len(desc)}",
|
||||||
)
|
)
|
||||||
update_description(engine_name, searxng_locale, desc, 'wikipedia')
|
update_description(engine_name, searxng_locale, desc, "wikipedia")
|
||||||
|
|
||||||
|
|
||||||
def normalize_url(url):
|
def normalize_url(url: str):
|
||||||
url = url.replace('{language}', 'en')
|
url = url.replace("{language}", "en")
|
||||||
url = urlparse(url)._replace(path='/', params='', query='', fragment='').geturl()
|
url = urlparse(url)._replace(path="/", params="", query="", fragment="").geturl()
|
||||||
url = url.replace('https://api.', 'https://')
|
url = url.replace("https://api.", "https://")
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
def fetch_website_description(engine_name, website):
|
def fetch_website_description(engine_name: str, website: str):
|
||||||
print(f"- fetch website descr: {engine_name} / {website}")
|
print(f"- fetch website descr: {engine_name} / {website}")
|
||||||
default_lang, default_description = get_website_description(website, None, None)
|
default_lang, default_description = get_website_description(website, None, None)
|
||||||
|
|
||||||
@@ -268,11 +300,11 @@ def fetch_website_description(engine_name, website):
|
|||||||
|
|
||||||
# to specify an order in where the most common languages are in front of the
|
# to specify an order in where the most common languages are in front of the
|
||||||
# language list ..
|
# language list ..
|
||||||
languages = ['en', 'es', 'pt', 'ru', 'tr', 'fr']
|
languages = ["en", "es", "pt", "ru", "tr", "fr"]
|
||||||
languages = languages + [l for l in LOCALE_NAMES if l not in languages]
|
languages = languages + [l for l in LOCALE_NAMES if l not in languages]
|
||||||
|
|
||||||
previous_matched_lang = None
|
previous_matched_lang: str | None = None
|
||||||
previous_count = 0
|
previous_count: int = 0
|
||||||
|
|
||||||
for lang in languages:
|
for lang in languages:
|
||||||
|
|
||||||
@@ -307,19 +339,15 @@ def fetch_website_description(engine_name, website):
|
|||||||
f" / fetched lang: {fetched_lang:7} / len(desc): {len(desc)}"
|
f" / fetched lang: {fetched_lang:7} / len(desc): {len(desc)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
matched_lang = match_locale(fetched_lang, LOCALE_NAMES.keys(), fallback=lang)
|
matched_lang = match_locale(fetched_lang, list(LOCALE_NAMES.keys())) or lang
|
||||||
update_description(engine_name, matched_lang, desc, website, replace=False)
|
update_description(engine_name, matched_lang, desc, website, replace=False)
|
||||||
|
|
||||||
|
|
||||||
def fetch_website_descriptions():
|
def fetch_website_descriptions():
|
||||||
print('Fetching website descriptions')
|
print("Fetching website descriptions")
|
||||||
for engine_name, engine in searx.engines.engines.items():
|
for engine_name, engine in searx.engines.engines.items():
|
||||||
website = getattr(engine, "about", {}).get('website')
|
website = engine.about.website or getattr(engine, "search_url", "") or getattr(engine, "base_url", "")
|
||||||
if website is None and hasattr(engine, "search_url"):
|
if website:
|
||||||
website = normalize_url(getattr(engine, "search_url"))
|
|
||||||
if website is None and hasattr(engine, "base_url"):
|
|
||||||
website = normalize_url(getattr(engine, "base_url"))
|
|
||||||
if website is not None:
|
|
||||||
fetch_website_description(engine_name, website)
|
fetch_website_description(engine_name, website)
|
||||||
|
|
||||||
|
|
||||||
@@ -328,30 +356,32 @@ def get_engine_descriptions_filename():
|
|||||||
|
|
||||||
|
|
||||||
def get_output():
|
def get_output():
|
||||||
|
"""Summary of the results, once known descriptions are not duplicated,
|
||||||
|
instead a reference is provided.
|
||||||
|
|
||||||
|
- from: ``descriptions[engine][language] = [description, source]``
|
||||||
|
- to: ``output[language][engine] = description_and_source``
|
||||||
|
|
||||||
|
``description_and_source`` can be:
|
||||||
|
|
||||||
|
- ``[description, source]``
|
||||||
|
- ``description`` (if source = "wikipedia")
|
||||||
|
- ``[f"engine:lang", "ref"]`` reference to another existing description
|
||||||
|
|
||||||
"""
|
"""
|
||||||
From descriptions[engine][language] = [description, source]
|
output: dict[str, dict[str, list[str] | str]] = {locale: {} for locale in LOCALE_NAMES}
|
||||||
To
|
seen_descriptions: dict[str, tuple[str, str]] = {}
|
||||||
|
|
||||||
* output[language][engine] = description_and_source
|
for engine_name, lang_descriptions in sorted(descriptions.items()):
|
||||||
* description_and_source can be:
|
for language, descr in sorted(lang_descriptions.items()):
|
||||||
* [description, source]
|
if descr[0] in seen_descriptions:
|
||||||
* description (if source = "wikipedia")
|
ref = seen_descriptions[descr[0]]
|
||||||
* [f"engine:lang", "ref"] (reference to another existing description)
|
descr = [f"{ref[0]}:{ref[1]}", "ref"]
|
||||||
"""
|
|
||||||
output = {locale: {} for locale in LOCALE_NAMES}
|
|
||||||
|
|
||||||
seen_descriptions = {}
|
|
||||||
|
|
||||||
for engine_name, lang_descriptions in descriptions.items():
|
|
||||||
for language, description in lang_descriptions.items():
|
|
||||||
if description[0] in seen_descriptions:
|
|
||||||
ref = seen_descriptions[description[0]]
|
|
||||||
description = [f'{ref[0]}:{ref[1]}', 'ref']
|
|
||||||
else:
|
else:
|
||||||
seen_descriptions[description[0]] = (engine_name, language)
|
seen_descriptions[descr[0]] = (engine_name, language)
|
||||||
if description[1] == 'wikipedia':
|
if descr[1] == "wikipedia":
|
||||||
description = description[0]
|
descr = descr[0]
|
||||||
output.setdefault(language, {}).setdefault(engine_name, description)
|
output.setdefault(language, {}).setdefault(engine_name, descr)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@@ -363,8 +393,8 @@ def main():
|
|||||||
fetch_website_descriptions()
|
fetch_website_descriptions()
|
||||||
|
|
||||||
output = get_output()
|
output = get_output()
|
||||||
with DATA_FILE.open('w', encoding='utf8') as f:
|
with DATA_FILE.open("w", encoding="utf8") as f:
|
||||||
f.write(json.dumps(output, indent=1, separators=(',', ':'), sort_keys=True, ensure_ascii=False))
|
f.write(json.dumps(output, indent=1, separators=(",", ":"), sort_keys=True, ensure_ascii=False))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user