2021-01-13 10:31:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2015-05-02 13:45:17 +00:00
|
|
|
"""
|
2021-01-13 10:31:25 +00:00
|
|
|
Github (IT)
|
2015-05-02 13:45:17 +00:00
|
|
|
"""
|
2014-09-02 15:37:47 +00:00
|
|
|
|
2013-10-20 19:53:49 +00:00
|
|
|
from json import loads
|
2020-08-06 15:42:46 +00:00
|
|
|
from urllib.parse import urlencode
|
2013-10-20 19:53:49 +00:00
|
|
|
|
2021-01-13 10:31:25 +00:00
|
|
|
# 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',
|
|
|
|
}
|
|
|
|
|
2014-09-02 15:37:47 +00:00
|
|
|
# engine dependent config
|
2021-12-22 15:58:52 +00:00
|
|
|
categories = ['it', 'repos']
|
2013-10-20 19:53:49 +00:00
|
|
|
|
2014-09-02 15:37:47 +00:00
|
|
|
# search-url
|
2014-01-20 01:31:20 +00:00
|
|
|
search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}' # noqa
|
|
|
|
|
|
|
|
accept_header = 'application/vnd.github.preview.text-match+json'
|
|
|
|
|
2013-10-20 19:53:49 +00:00
|
|
|
|
2014-09-02 15:37:47 +00:00
|
|
|
# do search-request
|
2013-10-20 19:53:49 +00:00
|
|
|
def request(query, params):
|
2013-10-23 21:55:37 +00:00
|
|
|
params['url'] = search_url.format(query=urlencode({'q': query}))
|
2014-09-02 15:37:47 +00:00
|
|
|
|
2014-01-20 01:31:20 +00:00
|
|
|
params['headers']['Accept'] = accept_header
|
2014-09-02 15:37:47 +00:00
|
|
|
|
2013-10-20 19:53:49 +00:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
2014-09-02 15:37:47 +00:00
|
|
|
# get response from search-request
|
2013-10-20 19:53:49 +00:00
|
|
|
def response(resp):
|
|
|
|
results = []
|
2014-09-02 15:37:47 +00:00
|
|
|
|
2013-10-20 19:53:49 +00:00
|
|
|
search_res = loads(resp.text)
|
2014-09-02 15:37:47 +00:00
|
|
|
|
2022-09-27 15:01:00 +00:00
|
|
|
# check if items are received
|
2015-05-02 13:45:17 +00:00
|
|
|
if 'items' not in search_res:
|
2014-09-02 15:37:47 +00:00
|
|
|
return []
|
|
|
|
|
|
|
|
# parse results
|
2013-10-20 19:53:49 +00:00
|
|
|
for res in search_res['items']:
|
|
|
|
title = res['name']
|
|
|
|
url = res['html_url']
|
2014-09-02 15:37:47 +00:00
|
|
|
|
2013-10-23 10:24:09 +00:00
|
|
|
if res['description']:
|
2016-12-09 10:44:24 +00:00
|
|
|
content = res['description'][:500]
|
2013-10-23 10:24:09 +00:00
|
|
|
else:
|
|
|
|
content = ''
|
2014-09-02 15:37:47 +00:00
|
|
|
|
|
|
|
# append result
|
2021-12-27 08:26:22 +00:00
|
|
|
results.append({'url': url, 'title': title, 'content': content})
|
2014-09-02 15:37:47 +00:00
|
|
|
|
|
|
|
# return results
|
2013-10-20 19:53:49 +00:00
|
|
|
return results
|