logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

github.py (1299B)


  1. """
  2. Github (It)
  3. @website https://github.com/
  4. @provide-api yes (https://developer.github.com/v3/)
  5. @using-api yes
  6. @results JSON
  7. @stable yes (using api)
  8. @parse url, title, content
  9. """
  10. from json import loads
  11. from searx.url_utils import urlencode
  12. # engine dependent config
  13. categories = ['it']
  14. # search-url
  15. search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}' # noqa
  16. accept_header = 'application/vnd.github.preview.text-match+json'
  17. # do search-request
  18. def request(query, params):
  19. params['url'] = search_url.format(query=urlencode({'q': query}))
  20. params['headers']['Accept'] = accept_header
  21. return params
  22. # get response from search-request
  23. def response(resp):
  24. results = []
  25. search_res = loads(resp.text)
  26. # check if items are recieved
  27. if 'items' not in search_res:
  28. return []
  29. # parse results
  30. for res in search_res['items']:
  31. title = res['name']
  32. url = res['html_url']
  33. if res['description']:
  34. content = res['description'][:500]
  35. else:
  36. content = ''
  37. # append result
  38. results.append({'url': url,
  39. 'title': title,
  40. 'content': content})
  41. # return results
  42. return results