1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-18 02:10:12 +01:00
searxng/searx/engines/github.py

33 lines
887 B
Python
Raw Normal View History

2013-10-20 21:53:49 +02:00
from urllib import urlencode
from json import loads
2013-10-22 23:17:22 +02:00
from cgi import escape
2013-10-20 21:53:49 +02:00
categories = ['it']
2014-01-20 02:31:20 +01:00
search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}' # noqa
accept_header = 'application/vnd.github.preview.text-match+json'
2013-10-20 21:53:49 +02:00
def request(query, params):
global search_url
2013-10-23 23:55:37 +02:00
params['url'] = search_url.format(query=urlencode({'q': query}))
2014-01-20 02:31:20 +01:00
params['headers']['Accept'] = accept_header
2013-10-20 21:53:49 +02:00
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 21:53:49 +02:00
results.append({'url': url, 'title': title, 'content': content})
return results