mirror of
https://github.com/searxng/searxng
synced 2024-11-18 15:26:25 +00:00
3d96a9839a
This patch was generated by black [1]:: make format.python [1] https://github.com/psf/black Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
62 lines
1.3 KiB
Python
62 lines
1.3 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
Github (IT)
|
|
"""
|
|
|
|
from json import loads
|
|
from urllib.parse import urlencode
|
|
|
|
# about
|
|
about = {
|
|
"website": 'https://github.com/',
|
|
"wikidata_id": 'Q364',
|
|
"official_api_documentation": 'https://developer.github.com/v3/',
|
|
"use_official_api": True,
|
|
"require_api_key": False,
|
|
"results": 'JSON',
|
|
}
|
|
|
|
# engine dependent config
|
|
categories = ['it']
|
|
|
|
# search-url
|
|
search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}' # noqa
|
|
|
|
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['headers']['Accept'] = accept_header
|
|
|
|
return params
|
|
|
|
|
|
# get response from search-request
|
|
def response(resp):
|
|
results = []
|
|
|
|
search_res = loads(resp.text)
|
|
|
|
# check if items are recieved
|
|
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})
|
|
|
|
# return results
|
|
return results
|