mwmbl.py 1.3 KB

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