.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
github.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Github (IT)
3
4"""
5
6from urllib.parse import urlencode
7from dateutil import parser
8
9# about
10about = {
11 "website": 'https://github.com/',
12 "wikidata_id": 'Q364',
13 "official_api_documentation": 'https://developer.github.com/v3/',
14 "use_official_api": True,
15 "require_api_key": False,
16 "results": 'JSON',
17}
18
19# engine dependent config
20categories = ['it', 'repos']
21
22# search-url
23search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}'
24accept_header = 'application/vnd.github.preview.text-match+json'
25
26
27def request(query, params):
28
29 params['url'] = search_url.format(query=urlencode({'q': query}))
30 params['headers']['Accept'] = accept_header
31
32 return params
33
34
35def response(resp):
36 results = []
37
38 for item in resp.json().get('items', []):
39 content = [item.get(i) for i in ['language', 'description'] if item.get(i)]
40
41 # license can be None
42 lic = item.get('license') or {}
43 lic_url = None
44 if lic.get('spdx_id'):
45 lic_url = f"https://spdx.org/licenses/{lic.get('spdx_id')}.html"
46
47 results.append(
48 {
49 'template': 'packages.html',
50 'url': item.get('html_url'),
51 'title': item.get('full_name'),
52 'content': ' / '.join(content),
53 'thumbnail': item.get('owner', {}).get('avatar_url'),
54 'package_name': item.get('name'),
55 # 'version': item.get('updated_at'),
56 'maintainer': item.get('owner', {}).get('login'),
57 'publishedDate': parser.parse(item.get("updated_at") or item.get("created_at")),
58 'tags': item.get('topics', []),
59 'popularity': item.get('stargazers_count'),
60 'license_name': lic.get('name'),
61 'license_url': lic_url,
62 'homepage': item.get('homepage'),
63 'source_code_url': item.get('clone_url'),
64 }
65 )
66
67 return results
request(query, params)
Definition github.py:27