mwmbl.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # lint: pylint
  3. """Mwmbl_ is a non-profit, ad-free, free-libre and free-lunch search engine with
  4. a focus on useability and speed.
  5. .. hint::
  6. At the moment it is little more than an idea together with a proof of concept
  7. implementation of the web front-end and search technology on a small index.
  8. Mwmbl_ does not support regions, languages, safe-search or time range.
  9. search.
  10. .. _Mwmbl: https://github.com/mwmbl/mwmbl
  11. """
  12. from urllib.parse import urlencode
  13. about = {
  14. "website": 'https://github.com/mwmbl/mwmbl',
  15. "official_api_documentation": 'https://api.mwmbl.org/docs',
  16. "use_official_api": True,
  17. "require_api_key": False,
  18. "results": 'JSON',
  19. }
  20. paging = False
  21. categories = ['general']
  22. api_url = "https://api.mwmbl.org"
  23. def request(query, params):
  24. params['url'] = f"{api_url}/search?{urlencode({'s': query})}"
  25. return params
  26. def response(resp):
  27. results = []
  28. json_results = resp.json()
  29. for result in json_results:
  30. title_parts = [title['value'] for title in result['title']]
  31. results.append(
  32. {
  33. 'url': result['url'],
  34. 'title': ''.join(title_parts),
  35. 'content': result['extract'][0]['value'],
  36. }
  37. )
  38. return results