mwmbl.py 914 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # lint: pylint
  3. """mwmbl (general)
  4. """
  5. from urllib.parse import urlencode
  6. about = {
  7. "website": 'https://github.com/mwmbl/mwmbl',
  8. "official_api_documentation": 'https://api.mwmbl.org/docs',
  9. "use_official_api": True,
  10. "require_api_key": False,
  11. "results": 'JSON',
  12. }
  13. paging = False
  14. categories = ['general']
  15. api_url = "https://api.mwmbl.org"
  16. def request(query, params):
  17. params['url'] = f"{api_url}/search?{urlencode({'s': query})}"
  18. return params
  19. def response(resp):
  20. results = []
  21. json_results = resp.json()
  22. for result in json_results:
  23. title_parts = [title['value'] for title in result['title']]
  24. results.append(
  25. {
  26. 'url': result['url'],
  27. 'title': ''.join(title_parts),
  28. 'content': result['extract'][0]['value'],
  29. }
  30. )
  31. return results