summaryrefslogtreecommitdiff
path: root/searx/engines/github.py
blob: 591fd14a78bd4068fba69e040e5c3b754cd93898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from urllib import urlencode
from json import loads
from cgi import escape

categories = ['it']

search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&'

def request(query, params):
    global search_url
    params['url'] = search_url + urlencode({'q': query})
    params['headers']['Accept'] = 'application/vnd.github.preview.text-match+json'
    return params


def response(resp):
    results = []
    search_res = loads(resp.text)
    if not 'items' in search_res:
        return results
    for res in search_res['items']:
        title = res['name']
        url = res['html_url']
        content = escape(res['description'][:500])
        results.append({'url': url, 'title': title, 'content': content})
    return results