summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2024-02-23 15:55:47 +0100
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-02-25 14:56:57 +0100
commitb683aa63fb3e1689c28bd4b762b4ad962e8e232c (patch)
tree7026eb4d6168f9365ed756fb1e4109bdff4c9da5 /searx
parent1d6f475fbce9ec694ecebee18384c68be440a2c2 (diff)
downloadsearxng-b683aa63fb3e1689c28bd4b762b4ad962e8e232c.tar.gz
searxng-b683aa63fb3e1689c28bd4b762b4ad962e8e232c.zip
[feat] github: use packages template
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/github.py61
1 files changed, 34 insertions, 27 deletions
diff --git a/searx/engines/github.py b/searx/engines/github.py
index 3180418ef..36eca4c53 100644
--- a/searx/engines/github.py
+++ b/searx/engines/github.py
@@ -1,10 +1,11 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
-"""
- Github (IT)
+# lint: pylint
+
+"""Github (IT)
"""
-from json import loads
from urllib.parse import urlencode
+from dateutil import parser
# about
about = {
@@ -20,42 +21,48 @@ about = {
categories = ['it', 'repos']
# search-url
-search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}' # noqa
-
+search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}'
accept_header = 'application/vnd.github.preview.text-match+json'
-# do search-request
def request(query, params):
- params['url'] = search_url.format(query=urlencode({'q': query}))
+ params['url'] = search_url.format(query=urlencode({'q': query}))
params['headers']['Accept'] = accept_header
return params
-# get response from search-request
def response(resp):
results = []
- search_res = loads(resp.text)
-
- # check if items are received
- if 'items' not in search_res:
- return []
-
- # parse results
- for res in search_res['items']:
- title = res['name']
- url = res['html_url']
-
- if res['description']:
- content = res['description'][:500]
- else:
- content = ''
-
- # append result
- results.append({'url': url, 'title': title, 'content': content})
+ for item in resp.json().get('items', []):
+ content = [item.get(i) for i in ['language', 'description'] if item.get(i)]
+
+ # license can be None
+ lic = item.get('license') or {}
+ lic_url = None
+ if lic.get('spdx_id'):
+ lic_url = f"https://spdx.org/licenses/{lic.get('spdx_id')}.html"
+
+ 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'),
+ # 'version': item.get('updated_at'),
+ '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'),
+ 'license_name': lic.get('name'),
+ 'license_url': lic_url,
+ 'homepage': item.get('homepage'),
+ 'source_code_url': item.get('clone_url'),
+ }
+ )
- # return results
return results