summaryrefslogtreecommitdiff
path: root/searx/plugins/ahmia_filter.py
diff options
context:
space:
mode:
authorJohannes 'josch' Schauer <josch@debian.org>2021-01-19 12:54:47 +0100
committerJohannes 'josch' Schauer <josch@debian.org>2021-01-19 12:54:47 +0100
commit7a1db4de351875bebb4a8e7ffbe6710ad5b518c5 (patch)
tree41fc39a14842780c6ea061b29a00888e8071ffa8 /searx/plugins/ahmia_filter.py
parent075e7e02683d9db1b303de8e8c17ff7da4c62510 (diff)
New upstream version 0.18.0+dfsg1
Diffstat (limited to 'searx/plugins/ahmia_filter.py')
-rw-r--r--searx/plugins/ahmia_filter.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/searx/plugins/ahmia_filter.py b/searx/plugins/ahmia_filter.py
new file mode 100644
index 0000000..83b05e4
--- /dev/null
+++ b/searx/plugins/ahmia_filter.py
@@ -0,0 +1,33 @@
+'''
+ SPDX-License-Identifier: AGPL-3.0-or-later
+'''
+
+from hashlib import md5
+from searx.data import ahmia_blacklist_loader
+
+name = "Ahmia blacklist"
+description = "Filter out onion results that appear in Ahmia's blacklist. (See https://ahmia.fi/blacklist)"
+default_on = True
+preference_section = 'onions'
+
+ahmia_blacklist = None
+
+
+def get_ahmia_blacklist():
+ global ahmia_blacklist
+ if not ahmia_blacklist:
+ ahmia_blacklist = ahmia_blacklist_loader()
+ return ahmia_blacklist
+
+
+def not_blacklisted(result):
+ if not result.get('is_onion') or not result.get('parsed_url'):
+ return True
+ result_hash = md5(result['parsed_url'].hostname.encode()).hexdigest()
+ return result_hash not in get_ahmia_blacklist()
+
+
+def post_search(request, search):
+ filtered_results = list(filter(not_blacklisted, search.result_container._merged_results))
+ search.result_container._merged_results = filtered_results
+ return True