Browse Source

Use a plugin to filter results

Arend-Jan Tetteroo 5 years ago
commit
12444ebee4
1 changed files with 46 additions and 0 deletions
  1. 46 0
      only_show_green_results.py

+ 46 - 0
only_show_green_results.py

@@ -0,0 +1,46 @@
+'''
+searx is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+searx is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with searx. If not, see < http://www.gnu.org/licenses/ >.
+
+(C) 2015 by Adam Tauber, <asciimoo@gmail.com>
+'''
+
+from flask_babel import gettext
+import re
+from searx.url_utils import urlunparse, parse_qsl, urlencode
+
+name = gettext('Only show green hosted results')
+description = gettext('Any results not being hosted on green infrastructure will be filtered')
+default_on = True
+preference_section = 'privacy'
+
+# attach callback to the post search hook
+#  request: flask request object
+#  ctx: the whole local context of the pre search hook
+def post_search(request, search):
+    print search
+
+
+def on_result(request, search, result):
+    print result
+
+    if 'parsed_url' not in result:
+        return True
+
+    print result['url']
+
+    result['green'] = False
+    result['template'] = 'green.html'
+    # @todo hook up the url to our greencheck tool and return true if green/false if grey
+
+    return True