searxng/searx/engines/github.py

30 lines
847 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']
2013-10-23 21:55:37 +00:00
search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}'
2013-10-20 19:53:49 +00:00
def request(query, params):
global search_url
2013-10-23 21:55:37 +00:00
params['url'] = search_url.format(query=urlencode({'q': query}))
2013-10-20 19:53:49 +00:00
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