From 3a71d4b1757a6802fc36c637918bf0dc65737415 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 24 May 2021 16:19:06 +0200 Subject: [PATCH 1/2] [pylint] searx/engines/genius.py, add logger & normalized indentation - pylint searx/engines/genius.py - add logger and log ignored exceptions - normalized various indentation Signed-off-by: Markus Heiser --- searx/engines/genius.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/searx/engines/genius.py b/searx/engines/genius.py index 9f6a8cd5f..86bab1f8f 100644 --- a/searx/engines/genius.py +++ b/searx/engines/genius.py @@ -1,12 +1,17 @@ # SPDX-License-Identifier: AGPL-3.0-or-later -""" - Genius +# lint: pylint +# pylint: disable=invalid-name, missing-function-docstring +"""Genius + """ from json import loads from urllib.parse import urlencode from datetime import datetime +from searx import logger +logger = logger.getChild('genius engine') + # about about = { "website": 'https://genius.com/', @@ -27,17 +32,20 @@ search_url = url + 'search/{index}?{query}&page={pageno}&per_page={page_size}' def request(query, params): - params['url'] = search_url.format(query=urlencode({'q': query}), - index='multi', - page_size=page_size, - pageno=params['pageno']) + params['url'] = search_url.format( + query=urlencode({'q': query}), + index='multi', + page_size=page_size, + pageno=params['pageno'], + ) return params def parse_lyric(hit): try: content = hit['highlights'][0]['value'] - except: + except Exception as e: # pylint: disable=broad-except + logger.error(e, exc_info=True) content = '' timestamp = hit['result']['lyrics_updated_at'] result = {'url': hit['result']['url'], @@ -51,11 +59,12 @@ def parse_lyric(hit): def parse_artist(hit): - result = {'url': hit['result']['url'], - 'title': hit['result']['name'], - 'content': '', - 'thumbnail': hit['result']['image_url'], - 'template': 'videos.html'} + result = { + 'url': hit['result']['url'], + 'title': hit['result']['name'], + 'content': '', + 'thumbnail': hit['result']['image_url'], + } return result @@ -68,8 +77,8 @@ def parse_album(hit): 'template': 'videos.html'} try: year = hit['result']['release_date_components']['year'] - except: - pass + except Exception as e: # pylint: disable=broad-except + logger.error(e, exc_info=True) else: if year: result.update({'content': 'Released: {}'.format(year)}) From f963759ccc8b7598db780fc112551c03aadde51e Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 24 May 2021 16:31:14 +0200 Subject: [PATCH 2/2] [fix] engine genius should not use the video template Remove 'template' from result. Engine genius should not use the video template. BTW: fix indentations Signed-off-by: Markus Heiser --- searx/engines/genius.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/searx/engines/genius.py b/searx/engines/genius.py index 86bab1f8f..9d701a8de 100644 --- a/searx/engines/genius.py +++ b/searx/engines/genius.py @@ -48,11 +48,12 @@ def parse_lyric(hit): logger.error(e, exc_info=True) content = '' timestamp = hit['result']['lyrics_updated_at'] - result = {'url': hit['result']['url'], - 'title': hit['result']['full_title'], - 'content': content, - 'thumbnail': hit['result']['song_art_image_thumbnail_url'], - 'template': 'videos.html'} + result = { + 'url': hit['result']['url'], + 'title': hit['result']['full_title'], + 'content': content, + 'thumbnail': hit['result']['song_art_image_thumbnail_url'], + } if timestamp: result.update({'publishedDate': datetime.fromtimestamp(timestamp)}) return result @@ -69,12 +70,12 @@ def parse_artist(hit): def parse_album(hit): - result = {'url': hit['result']['url'], - 'title': hit['result']['full_title'], - 'thumbnail': hit['result']['cover_art_url'], - 'content': '', - # 'thumbnail': hit['result']['cover_art_thumbnail_url'], - 'template': 'videos.html'} + result = { + 'url': hit['result']['url'], + 'title': hit['result']['full_title'], + 'thumbnail': hit['result']['cover_art_url'], + 'content': '', + } try: year = hit['result']['release_date_components']['year'] except Exception as e: # pylint: disable=broad-except