ahmia_filter.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # pylint: disable=missing-module-docstring
  3. from __future__ import annotations
  4. from hashlib import md5
  5. import flask
  6. from searx.data import ahmia_blacklist_loader
  7. from searx import get_setting
  8. name = "Ahmia blacklist"
  9. description = "Filter out onion results that appear in Ahmia's blacklist. (See https://ahmia.fi/blacklist)"
  10. default_on = True
  11. preference_section = 'onions'
  12. ahmia_blacklist: list = []
  13. def on_result(_request, _search, result) -> bool:
  14. if not getattr(result, 'is_onion', None) or not getattr(result, 'parsed_url', None):
  15. return True
  16. result_hash = md5(result['parsed_url'].hostname.encode()).hexdigest()
  17. return result_hash not in ahmia_blacklist
  18. def init(app=flask.Flask) -> bool: # pylint: disable=unused-argument
  19. global ahmia_blacklist # pylint: disable=global-statement
  20. if not get_setting("outgoing.using_tor_proxy"):
  21. # disable the plugin
  22. return False
  23. ahmia_blacklist = ahmia_blacklist_loader()
  24. return True