From 7f07fe25e095241f78c873f9cd931978d8dbea4e Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Mon, 27 Apr 2020 20:47:54 +0200 Subject: [PATCH] Fix no result when no blacklist_words --- pynyaata/config.py | 2 +- pynyaata/connectors/nyaa.py | 5 ++--- pynyaata/connectors/pantsu.py | 5 ++--- pynyaata/connectors/yggtorrent.py | 5 ++--- pynyaata/utils.py | 6 +++++- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pynyaata/config.py b/pynyaata/config.py index eef232d..94d0eb9 100644 --- a/pynyaata/config.py +++ b/pynyaata/config.py @@ -13,7 +13,7 @@ ADMIN_USERNAME = environ.get('ADMIN_USERNAME', 'admin') ADMIN_PASSWORD = generate_password_hash(environ.get('ADMIN_PASSWORD', 'secret')) APP_PORT = environ.get('FLASK_PORT', 5000) CACHE_TIMEOUT = environ.get('CACHE_TIMEOUT', 60 * 60) -BLACKLIST_WORDS = environ.get('BLACKLIST_WORDS', '').split(',') +BLACKLIST_WORDS = environ.get('BLACKLIST_WORDS', '').split(',') if environ.get('BLACKLIST_WORDS', '') else [] MYSQL_ENABLED = False app = Flask(__name__) diff --git a/pynyaata/connectors/nyaa.py b/pynyaata/connectors/nyaa.py index 7609d61..939b11d 100644 --- a/pynyaata/connectors/nyaa.py +++ b/pynyaata/connectors/nyaa.py @@ -1,8 +1,7 @@ from bs4 import BeautifulSoup from .core import ConnectorCore, ConnectorReturn, ConnectorCache, curl_content -from ..config import BLACKLIST_WORDS -from ..utils import parse_date, link_exist_in_db +from ..utils import parse_date, link_exist_in_db, check_blacklist_words class Nyaa(ConnectorCore): @@ -52,7 +51,7 @@ class Nyaa(ConnectorCore): url_safe = url.get_text() - if any(word.lower() in url_safe.lower() for word in BLACKLIST_WORDS): + if check_blacklist_words(url_safe): continue valid_trs = valid_trs + 1 diff --git a/pynyaata/connectors/pantsu.py b/pynyaata/connectors/pantsu.py index 56ed791..6cfeec6 100644 --- a/pynyaata/connectors/pantsu.py +++ b/pynyaata/connectors/pantsu.py @@ -1,8 +1,7 @@ from bs4 import BeautifulSoup from .core import ConnectorCore, ConnectorReturn, ConnectorCache, curl_content -from ..config import BLACKLIST_WORDS -from ..utils import parse_date, link_exist_in_db +from ..utils import parse_date, link_exist_in_db, check_blacklist_words class Pantsu(ConnectorCore): @@ -44,7 +43,7 @@ class Pantsu(ConnectorCore): url = tds[1].a url_safe = url.get_text() - if any(word.lower() in url_safe.lower() for word in BLACKLIST_WORDS): + if check_blacklist_words(url_safe): continue valid_trs = valid_trs + 1 diff --git a/pynyaata/connectors/yggtorrent.py b/pynyaata/connectors/yggtorrent.py index 39f8937..f17a793 100644 --- a/pynyaata/connectors/yggtorrent.py +++ b/pynyaata/connectors/yggtorrent.py @@ -5,8 +5,7 @@ from urllib.parse import quote from bs4 import BeautifulSoup from .core import ConnectorCore, ConnectorReturn, ConnectorCache, curl_content -from ..config import BLACKLIST_WORDS -from ..utils import parse_date, link_exist_in_db +from ..utils import parse_date, link_exist_in_db, check_blacklist_words class YggTorrent(ConnectorCore): @@ -52,7 +51,7 @@ class YggTorrent(ConnectorCore): url = tds[1].a url_safe = url.get_text() - if any(word.lower() in url_safe.lower() for word in BLACKLIST_WORDS): + if check_blacklist_words(url_safe): continue valid_trs = valid_trs + 1 diff --git a/pynyaata/utils.py b/pynyaata/utils.py index 15f9f6a..c4e1fed 100644 --- a/pynyaata/utils.py +++ b/pynyaata/utils.py @@ -3,7 +3,7 @@ from datetime import datetime from dateparser import parse -from . import MYSQL_ENABLED +from .config import MYSQL_ENABLED, BLACKLIST_WORDS def link_exist_in_db(href): @@ -41,3 +41,7 @@ def clean_model(obj): except AttributeError: pass return obj + + +def check_blacklist_words(url): + return any(word.lower() in url.lower() for word in BLACKLIST_WORDS)