diff options
author | Thomas Pointhuber <thomas.pointhuber@gmx.at> | 2014-09-02 17:37:47 +0200 |
---|---|---|
committer | Thomas Pointhuber <thomas.pointhuber@gmx.at> | 2014-09-02 17:37:47 +0200 |
commit | 334a286c18652423447aff589ec0f25406e4d8ea (patch) | |
tree | 444e6adb00d4718590fb06c0a3a840ed770b8ab5 /searx/engines/github.py | |
parent | c5d83059d537d8efb296ffbe743828a884ac4e10 (diff) | |
download | searxng-334a286c18652423447aff589ec0f25406e4d8ea.tar.gz searxng-334a286c18652423447aff589ec0f25406e4d8ea.zip |
update github engine and add comments
Diffstat (limited to 'searx/engines/github.py')
-rw-r--r-- | searx/engines/github.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/searx/engines/github.py b/searx/engines/github.py index d36797aba..53fec029f 100644 --- a/searx/engines/github.py +++ b/searx/engines/github.py @@ -1,31 +1,59 @@ +## Github (It) +# +# @website https://github.com/ +# @provide-api yes (https://developer.github.com/v3/) +# +# @using-api yes +# @results JSON +# @stable yes (using api) +# @parse url, title, content + from urllib import urlencode from json import loads from cgi import escape +# engine dependent config categories = ['it'] +# search-url search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}' # noqa accept_header = 'application/vnd.github.preview.text-match+json' +# do search-request def request(query, params): params['url'] = search_url.format(query=urlencode({'q': query})) + params['headers']['Accept'] = accept_header + return params +# get response from search-request def response(resp): results = [] + search_res = loads(resp.text) + + # check if items are recieved if not 'items' in search_res: - return results + return [] + + # parse results for res in search_res['items']: title = res['name'] url = res['html_url'] + if res['description']: content = escape(res['description'][:500]) else: content = '' - results.append({'url': url, 'title': title, 'content': content}) + + # append result + results.append({'url': url, + 'title': title, + 'content': content}) + + # return results return results |