Browse Source

Hook up the green filter to the green check api

Arend-Jan Tetteroo 5 years ago
parent
commit
c1f406beb2
1 changed files with 10 additions and 4 deletions
  1. 10 4
      only_show_green_results.py

+ 10 - 4
only_show_green_results.py

@@ -18,6 +18,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
 from flask_babel import gettext
 import re
 from searx.url_utils import urlunparse, parse_qsl, urlencode
+import requests
 
 name = gettext('Only show green hosted results')
 description = gettext('Any results not being hosted on green infrastructure will be filtered')
@@ -32,15 +33,20 @@ def post_search(request, search):
 
 
 def on_result(request, search, result):
-    print result
-
     if 'parsed_url' not in result:
         return True
 
     print result['url']
 
-    result['green'] = False
+    # Put a green.html template up to have access over which results are shown or not
+    # @todo figure out a way to filter results in this callback so we don't need a special template
     result['template'] = 'green.html'
-    # @todo hook up the url to our greencheck tool and return true if green/false if grey
+
+    # @todo hook up the url to our greencheck tool instead of api here
+    response = requests.get("https://api.thegreenwebfoundation.org/greencheck/" + result['parsed_url'].netloc)
+    data = response.json()
+    #print(data['green'])
+
+    result['green'] = data['green']
 
     return True