searxng/searx/engines/github.py

30 lines
828 B
Python
Raw Normal View History

2013-10-20 19:53:49 +00:00
from urllib import urlencode
from json import loads
2013-10-22 21:17:22 +00:00
from cgi import escape
2013-10-20 19:53:49 +00:00
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']
if res['description']:
content = escape(res['description'][:500])
else:
content = ''
2013-10-20 19:53:49 +00:00
results.append({'url': url, 'title': title, 'content': content})
return results