2021-01-13 11:31:25 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2024-02-23 15:55:47 +01:00
|
|
|
# lint: pylint
|
|
|
|
|
|
|
|
"""Github (IT)
|
2015-05-02 15:45:17 +02:00
|
|
|
"""
|
2014-09-02 17:37:47 +02:00
|
|
|
|
2020-08-06 17:42:46 +02:00
|
|
|
from urllib.parse import urlencode
|
2024-02-23 15:55:47 +01:00
|
|
|
from dateutil import parser
|
2013-10-20 21:53:49 +02:00
|
|
|
|
2021-01-13 11:31:25 +01: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 17:37:47 +02:00
|
|
|
# engine dependent config
|
2021-12-22 16:58:52 +01:00
|
|
|
categories = ['it', 'repos']
|
2013-10-20 21:53:49 +02:00
|
|
|
|
2014-09-02 17:37:47 +02:00
|
|
|
# search-url
|
2024-02-23 15:55:47 +01:00
|
|
|
search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}'
|
2014-01-20 02:31:20 +01:00
|
|
|
accept_header = 'application/vnd.github.preview.text-match+json'
|
|
|
|
|
2013-10-20 21:53:49 +02:00
|
|
|
|
|
|
|
def request(query, params):
|
2014-09-02 17:37:47 +02:00
|
|
|
|
2024-02-23 15:55:47 +01:00
|
|
|
params['url'] = search_url.format(query=urlencode({'q': query}))
|
2014-01-20 02:31:20 +01:00
|
|
|
params['headers']['Accept'] = accept_header
|
2014-09-02 17:37:47 +02:00
|
|
|
|
2013-10-20 21:53:49 +02:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
2014-09-02 17:37:47 +02:00
|
|
|
|
2024-02-23 15:55:47 +01:00
|
|
|
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'),
|
|
|
|
}
|
|
|
|
)
|
2014-09-02 17:37:47 +02:00
|
|
|
|
2013-10-20 21:53:49 +02:00
|
|
|
return results
|