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

30 lines
847 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']
2013-10-23 23:55:37 +02:00
search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}'
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}))
2013-10-20 21:53:49 +02: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 21:53:49 +02:00
results.append({'url': url, 'title': title, 'content': content})
return results