summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-05-07 18:59:07 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-05-15 07:23:57 +0200
commit82b6c0d05f5e84568636eb27f2666271e2223aa8 (patch)
tree2650409acfc1bf3397a5a5e619ad5cc6b99463d3
parent60a373ad895360ccd0b2830ffa41cdc5aa737949 (diff)
downloadsearxng-82b6c0d05f5e84568636eb27f2666271e2223aa8.tar.gz
searxng-82b6c0d05f5e84568636eb27f2666271e2223aa8.zip
[feat] engine: implementation of gitea
-rw-r--r--docs/dev/engines/online/gitea.rst8
-rw-r--r--docs/index.rst2
-rw-r--r--searx/engines/gitea.py109
-rw-r--r--searx/settings.yml6
4 files changed, 124 insertions, 1 deletions
diff --git a/docs/dev/engines/online/gitea.rst b/docs/dev/engines/online/gitea.rst
new file mode 100644
index 000000000..745504e4d
--- /dev/null
+++ b/docs/dev/engines/online/gitea.rst
@@ -0,0 +1,8 @@
+.. _gitea engine:
+
+=====
+Gitea
+=====
+
+.. automodule:: searx.engines.gitea
+ :members:
diff --git a/docs/index.rst b/docs/index.rst
index 3db54734a..52d0f80ad 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -17,7 +17,7 @@ If you don't trust anyone, you can set up your own, see :ref:`installation`.
- :ref:`no user tracking / no profiling <SearXNG protect privacy>`
- script & cookies are optional
- secure, encrypted connections
- - :ref:`about 130 search engines <configured engines>`
+ - :ref:`about 200 search engines <configured engines>`
- `about 60 translations <https://translate.codeberg.org/projects/searxng/searxng/>`_
- about 100 `well maintained <https://uptime.searxng.org/>`__ instances on searx.space_
- :ref:`easy integration of search engines <demo online engine>`
diff --git a/searx/engines/gitea.py b/searx/engines/gitea.py
new file mode 100644
index 000000000..3775938ed
--- /dev/null
+++ b/searx/engines/gitea.py
@@ -0,0 +1,109 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+"""Engine to search in collaborative software platforms based on Gitea_.
+
+.. _Gitea: https://about.gitea.com/
+
+Configuration
+=============
+
+The engine has the following mandatory setting:
+
+- :py:obj:`base_url`
+
+Optional settings are:
+
+- :py:obj:`sort`
+- :py:obj:`order`
+- :py:obj:`page_size`
+
+.. code:: yaml
+
+ - name: gitea.com
+ engine: gitea
+ base_url: https://gitea.com
+ shortcut: gitea
+
+If you would like to use additional instances, just configure new engines in the
+:ref:`settings <settings engine>` and set the ``base_url``.
+
+
+Implementation
+==============
+
+"""
+
+from urllib.parse import urlencode
+from dateutil import parser
+
+about = {
+ "website": 'https://about.gitea.com',
+ "wikidata_id": None,
+ "official_api_documentation": 'https://docs.gitea.com/next/development/api-usage',
+ "use_official_api": True,
+ "require_api_key": False,
+ "results": 'JSON',
+}
+
+categories = ['it', 'repos']
+paging = True
+
+base_url: str = ''
+"""URL of the Gitea_ instance."""
+
+sort: str = "updated"
+"""Sort criteria, possible values:
+
+- ``updated`` (default)
+- ``alpha``
+- ``created``
+- ``size``
+- ``id``
+"""
+
+order = "desc"
+"""Sort order, possible values:
+
+- ``desc`` (default)
+- ``asc``
+"""
+
+page_size: int = 10
+"""Maximum number of results per page (default 10)."""
+
+
+def init(_):
+ if not base_url:
+ raise ValueError('gitea engine: base_url is unset')
+
+
+def request(query, params):
+ args = {'q': query, 'limit': page_size, 'sort': sort, 'order': order, 'page': params['pageno']}
+ params['url'] = f"{base_url}/api/v1/repos/search?{urlencode(args)}"
+
+ return params
+
+
+def response(resp):
+ results = []
+
+ for item in resp.json().get('data', []):
+ content = [item.get(i) for i in ['language', 'description'] if item.get(i)]
+
+ results.append(
+ {
+ 'template': 'packages.html',
+ 'url': item.get('html_url'),
+ 'title': item.get('full_name'),
+ 'content': ' / '.join(content),
+ 'img_src': item.get('owner', {}).get('avatar_url'),
+ 'package_name': item.get('name'),
+ 'maintainer': item.get('owner', {}).get('login'),
+ 'publishedDate': parser.parse(item.get("updated_at") or item.get("created_at")),
+ 'tags': item.get('topics', []),
+ 'popularity': item.get('stargazers_count'),
+ 'homepage': item.get('homepage'),
+ 'source_code_url': item.get('clone_url'),
+ }
+ )
+
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index 77f4b8339..35aa8cc6e 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -822,6 +822,12 @@ engines:
require_api_key: false
results: JSON
+ - name: gitea.com
+ engine: gitea
+ base_url: https://gitea.com
+ shortcut: gitea
+ disabled: true
+
- name: goodreads
engine: goodreads
shortcut: good