mwmbl.py 1.2 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. "use_official_api": True,
  15. "require_api_key": False,
  16. "results": 'JSON',
  17. }
  18. paging = False
  19. categories = ['general']
  20. api_url = "https://api.mwmbl.org/api/v1"
  21. def request(query, params):
  22. params['url'] = f"{api_url}/search/?{urlencode({'s': query})}"
  23. return params
  24. def response(resp):
  25. results = []
  26. json_results = resp.json()
  27. for result in json_results:
  28. title_parts = [title['value'] for title in result['title']]
  29. results.append(
  30. {
  31. 'url': result['url'],
  32. 'title': ''.join(title_parts),
  33. 'content': result['extract'][0]['value'],
  34. }
  35. )
  36. return results