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']
|
|
|
|
|
2014-01-20 01:31:20 +00: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 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}))
|
2014-01-20 01:31:20 +00:00
|
|
|
params['headers']['Accept'] = accept_header
|
2013-10-20 19:53:49 +00: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']
|
2013-10-23 10:24:09 +00:00
|
|
|
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
|