| 
				
			 | 
			
			
				@@ -4,7 +4,7 @@ 
			 | 
		
	
		
			
			| 
				4
			 | 
			
				4
			 | 
			
			
				  @website     http://www.faroo.com 
			 | 
		
	
		
			
			| 
				5
			 | 
			
				5
			 | 
			
			
				  @provide-api yes (http://www.faroo.com/hp/api/api.html), require API-key 
			 | 
		
	
		
			
			| 
				6
			 | 
			
				6
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				7
			 | 
			
				
			 | 
			
			
				- @using-api   yes 
			 | 
		
	
		
			
			| 
				
			 | 
			
				7
			 | 
			
			
				+ @using-api   no 
			 | 
		
	
		
			
			| 
				8
			 | 
			
				8
			 | 
			
			
				  @results     JSON 
			 | 
		
	
		
			
			| 
				9
			 | 
			
				9
			 | 
			
			
				  @stable      yes 
			 | 
		
	
		
			
			| 
				10
			 | 
			
				10
			 | 
			
			
				  @parse       url, title, content, publishedDate, img_src 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -20,18 +20,16 @@ categories = ['general', 'news'] 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				20
			 | 
			
			
				 paging = True 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				21
			 | 
			
			
				 language_support = True 
			 | 
		
	
		
			
			| 
				22
			 | 
			
				22
			 | 
			
			
				 number_of_results = 10 
			 | 
		
	
		
			
			| 
				23
			 | 
			
				
			 | 
			
			
				-api_key = None 
			 | 
		
	
		
			
			| 
				24
			 | 
			
				23
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				25
			 | 
			
				24
			 | 
			
			
				 # search-url 
			 | 
		
	
		
			
			| 
				26
			 | 
			
				25
			 | 
			
			
				 url = 'http://www.faroo.com/' 
			 | 
		
	
		
			
			| 
				27
			 | 
			
				
			 | 
			
			
				-search_url = url + 'api?{query}'\ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+search_url = url + 'instant.json?{query}'\ 
			 | 
		
	
		
			
			| 
				28
			 | 
			
				27
			 | 
			
			
				                       '&start={offset}'\ 
			 | 
		
	
		
			
			| 
				29
			 | 
			
				28
			 | 
			
			
				                       '&length={number_of_results}'\ 
			 | 
		
	
		
			
			| 
				30
			 | 
			
				29
			 | 
			
			
				                       '&l={language}'\ 
			 | 
		
	
		
			
			| 
				31
			 | 
			
				30
			 | 
			
			
				                       '&src={categorie}'\ 
			 | 
		
	
		
			
			| 
				32
			 | 
			
				31
			 | 
			
			
				                       '&i=false'\ 
			 | 
		
	
		
			
			| 
				33
			 | 
			
				
			 | 
			
			
				-                      '&f=json'\ 
			 | 
		
	
		
			
			| 
				34
			 | 
			
				
			 | 
			
			
				-                      '&key={api_key}'  # noqa 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+                      '&c=false' 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				33
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				36
			 | 
			
				34
			 | 
			
			
				 search_category = {'general': 'web', 
			 | 
		
	
		
			
			| 
				37
			 | 
			
				35
			 | 
			
			
				                    'news': 'news'} 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -57,21 +55,15 @@ def request(query, params): 
			 | 
		
	
		
			
			| 
				57
			 | 
			
				55
			 | 
			
			
				                                       number_of_results=number_of_results, 
			 | 
		
	
		
			
			| 
				58
			 | 
			
				56
			 | 
			
			
				                                       query=urlencode({'q': query}), 
			 | 
		
	
		
			
			| 
				59
			 | 
			
				57
			 | 
			
			
				                                       language=language, 
			 | 
		
	
		
			
			| 
				60
			 | 
			
				
			 | 
			
			
				-                                      categorie=categorie, 
			 | 
		
	
		
			
			| 
				61
			 | 
			
				
			 | 
			
			
				-                                      api_key=api_key) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+                                      categorie=categorie) 
			 | 
		
	
		
			
			| 
				62
			 | 
			
				59
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				63
			 | 
			
				
			 | 
			
			
				-    # using searx User-Agent 
			 | 
		
	
		
			
			| 
				64
			 | 
			
				
			 | 
			
			
				-    params['headers']['User-Agent'] = searx_useragent() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+    params['headers']['Referer'] = url 
			 | 
		
	
		
			
			| 
				65
			 | 
			
				61
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				66
			 | 
			
				62
			 | 
			
			
				     return params 
			 | 
		
	
		
			
			| 
				67
			 | 
			
				63
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				68
			 | 
			
				64
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				69
			 | 
			
				65
			 | 
			
			
				 # get response from search-request 
			 | 
		
	
		
			
			| 
				70
			 | 
			
				66
			 | 
			
			
				 def response(resp): 
			 | 
		
	
		
			
			| 
				71
			 | 
			
				
			 | 
			
			
				-    # HTTP-Code 401: api-key is not valide 
			 | 
		
	
		
			
			| 
				72
			 | 
			
				
			 | 
			
			
				-    if resp.status_code == 401: 
			 | 
		
	
		
			
			| 
				73
			 | 
			
				
			 | 
			
			
				-        raise Exception("API key is not valide") 
			 | 
		
	
		
			
			| 
				74
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				75
			 | 
			
				67
			 | 
			
			
				     # HTTP-Code 429: rate limit exceeded 
			 | 
		
	
		
			
			| 
				76
			 | 
			
				68
			 | 
			
			
				     if resp.status_code == 429: 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				69
			 | 
			
			
				         raise Exception("rate limit has been exceeded!") 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -86,31 +78,20 @@ def response(resp): 
			 | 
		
	
		
			
			| 
				86
			 | 
			
				78
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				87
			 | 
			
				79
			 | 
			
			
				     # parse results 
			 | 
		
	
		
			
			| 
				88
			 | 
			
				80
			 | 
			
			
				     for result in search_res['results']: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+        publishedDate = None 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+        result_json = {'url': result['url'], 
			 | 
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				+                        'title': result['title'], 
			 | 
		
	
		
			
			| 
				
			 | 
			
				84
			 | 
			
			
				+                        'content': result['kwic']} 
			 | 
		
	
		
			
			| 
				89
			 | 
			
				85
			 | 
			
			
				         if result['news']: 
			 | 
		
	
		
			
			| 
				90
			 | 
			
				
			 | 
			
			
				-            # timestamp (milliseconds since 1970) 
			 | 
		
	
		
			
			| 
				91
			 | 
			
				
			 | 
			
			
				-            publishedDate = datetime.datetime.fromtimestamp(result['date'] / 1000.0)  # noqa 
			 | 
		
	
		
			
			| 
				92
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				93
			 | 
			
				
			 | 
			
			
				-            # append news result 
			 | 
		
	
		
			
			| 
				94
			 | 
			
				
			 | 
			
			
				-            results.append({'url': result['url'], 
			 | 
		
	
		
			
			| 
				95
			 | 
			
				
			 | 
			
			
				-                            'title': result['title'], 
			 | 
		
	
		
			
			| 
				96
			 | 
			
				
			 | 
			
			
				-                            'publishedDate': publishedDate, 
			 | 
		
	
		
			
			| 
				97
			 | 
			
				
			 | 
			
			
				-                            'content': result['kwic']}) 
			 | 
		
	
		
			
			| 
				98
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				99
			 | 
			
				
			 | 
			
			
				-        else: 
			 | 
		
	
		
			
			| 
				100
			 | 
			
				
			 | 
			
			
				-            # append general result 
			 | 
		
	
		
			
			| 
				101
			 | 
			
				
			 | 
			
			
				-            # TODO, publishedDate correct? 
			 | 
		
	
		
			
			| 
				102
			 | 
			
				
			 | 
			
			
				-            results.append({'url': result['url'], 
			 | 
		
	
		
			
			| 
				103
			 | 
			
				
			 | 
			
			
				-                            'title': result['title'], 
			 | 
		
	
		
			
			| 
				104
			 | 
			
				
			 | 
			
			
				-                            'content': result['kwic']}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				86
			 | 
			
			
				+            result_json['publishedDate'] = \ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				87
			 | 
			
			
				+                    datetime.datetime.fromtimestamp(result['date'] / 1000.0) 
			 | 
		
	
		
			
			| 
				105
			 | 
			
				88
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				106
			 | 
			
				89
			 | 
			
			
				         # append image result if image url is set 
			 | 
		
	
		
			
			| 
				107
			 | 
			
				
			 | 
			
			
				-        # TODO, show results with an image like in faroo 
			 | 
		
	
		
			
			| 
				108
			 | 
			
				90
			 | 
			
			
				         if result['iurl']: 
			 | 
		
	
		
			
			| 
				109
			 | 
			
				
			 | 
			
			
				-            results.append({'template': 'images.html', 
			 | 
		
	
		
			
			| 
				110
			 | 
			
				
			 | 
			
			
				-                            'url': result['url'], 
			 | 
		
	
		
			
			| 
				111
			 | 
			
				
			 | 
			
			
				-                            'title': result['title'], 
			 | 
		
	
		
			
			| 
				112
			 | 
			
				
			 | 
			
			
				-                            'content': result['kwic'], 
			 | 
		
	
		
			
			| 
				113
			 | 
			
				
			 | 
			
			
				-                            'img_src': result['iurl']}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				91
			 | 
			
			
				+            result_json['template'] ='videos.html' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				92
			 | 
			
			
				+            result_json['thumbnail'] = result['iurl'] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				94
			 | 
			
			
				+        results.append(result_json) 
			 | 
		
	
		
			
			| 
				114
			 | 
			
				95
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				115
			 | 
			
				96
			 | 
			
			
				     # return results 
			 | 
		
	
		
			
			| 
				116
			 | 
			
				97
			 | 
			
			
				     return results 
			 |