diff options
author | misnyo <misnyo@misnyo.eu> | 2017-08-30 18:53:00 +0200 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2017-08-30 21:09:03 +0200 |
commit | 0607b167f85acc6c0ab4c641f14b53cb4190e445 (patch) | |
tree | 51272ea6b3c147811d27f5aa472a7ffaaa0389ff /searx | |
parent | 489bf0f6fd1b153d20aad2ca34706cc214d91558 (diff) | |
download | searxng-0607b167f85acc6c0ab4c641f14b53cb4190e445.tar.gz searxng-0607b167f85acc6c0ab4c641f14b53cb4190e445.zip |
[fix] faroo json api and image layout fixed
Diffstat (limited to 'searx')
-rw-r--r-- | searx/engines/faroo.py | 49 | ||||
-rw-r--r-- | searx/settings.yml | 9 |
2 files changed, 19 insertions, 39 deletions
diff --git a/searx/engines/faroo.py b/searx/engines/faroo.py index e24d1b7dc..5936c1902 100644 --- a/searx/engines/faroo.py +++ b/searx/engines/faroo.py @@ -4,7 +4,7 @@ @website http://www.faroo.com @provide-api yes (http://www.faroo.com/hp/api/api.html), require API-key - @using-api yes + @using-api no @results JSON @stable yes @parse url, title, content, publishedDate, img_src @@ -20,18 +20,16 @@ categories = ['general', 'news'] paging = True language_support = True number_of_results = 10 -api_key = None # search-url url = 'http://www.faroo.com/' -search_url = url + 'api?{query}'\ +search_url = url + 'instant.json?{query}'\ '&start={offset}'\ '&length={number_of_results}'\ '&l={language}'\ '&src={categorie}'\ '&i=false'\ - '&f=json'\ - '&key={api_key}' # noqa + '&c=false' search_category = {'general': 'web', 'news': 'news'} @@ -57,21 +55,15 @@ def request(query, params): number_of_results=number_of_results, query=urlencode({'q': query}), language=language, - categorie=categorie, - api_key=api_key) + categorie=categorie) - # using searx User-Agent - params['headers']['User-Agent'] = searx_useragent() + params['headers']['Referer'] = url return params # get response from search-request def response(resp): - # HTTP-Code 401: api-key is not valide - if resp.status_code == 401: - raise Exception("API key is not valide") - # HTTP-Code 429: rate limit exceeded if resp.status_code == 429: raise Exception("rate limit has been exceeded!") @@ -86,31 +78,20 @@ def response(resp): # parse results for result in search_res['results']: + publishedDate = None + result_json = {'url': result['url'], + 'title': result['title'], + 'content': result['kwic']} if result['news']: - # timestamp (milliseconds since 1970) - publishedDate = datetime.datetime.fromtimestamp(result['date'] / 1000.0) # noqa - - # append news result - results.append({'url': result['url'], - 'title': result['title'], - 'publishedDate': publishedDate, - 'content': result['kwic']}) - - else: - # append general result - # TODO, publishedDate correct? - results.append({'url': result['url'], - 'title': result['title'], - 'content': result['kwic']}) + result_json['publishedDate'] = \ + datetime.datetime.fromtimestamp(result['date'] / 1000.0) # append image result if image url is set - # TODO, show results with an image like in faroo if result['iurl']: - results.append({'template': 'images.html', - 'url': result['url'], - 'title': result['title'], - 'content': result['kwic'], - 'img_src': result['iurl']}) + result_json['template'] ='videos.html' + result_json['thumbnail'] = result['iurl'] + + results.append(result_json) # return results return results diff --git a/searx/settings.yml b/searx/settings.yml index bb06c4a0c..a98fb2663 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -189,11 +189,10 @@ engines: shortcut : et disabled : True -# api-key required: http://www.faroo.com/hp/api/api.html#key -# - name : faroo -# engine : faroo -# shortcut : fa -# api_key : 'apikey' # required! + - name : faroo + engine : faroo + shortcut : fa + disabled : True - name : 500px engine : www500px |