From f2db556f9063593ce16e1ab4def21efa669885f2 Mon Sep 17 00:00:00 2001 From: bobokun Date: Wed, 12 Jan 2022 18:48:54 -0500 Subject: [PATCH] optimize performance --- modules/qbittorrent.py | 10 +++++----- modules/util.py | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/qbittorrent.py b/modules/qbittorrent.py index f12fd5a..36abce3 100644 --- a/modules/qbittorrent.py +++ b/modules/qbittorrent.py @@ -113,7 +113,7 @@ class Qbt: if x.url.startswith('http'): status = x.status msg = x.msg.upper() - exception = set(["DOWN", "UNREACHABLE", "BAD GATEWAY", "TRACKER UNAVAILABLE"]) + exception = ["DOWN", "UNREACHABLE", "BAD GATEWAY", "TRACKER UNAVAILABLE"] if x.status == 2: working_tracker = True break @@ -469,7 +469,7 @@ class Qbt: if cfg_rem_unregistered or cfg_tag_error: if cfg_tag_error: separator("Tagging Torrents with Tracker Errors", space=False, border=False) elif cfg_rem_unregistered: separator("Removing Unregistered Torrents", space=False, border=False) - unreg_msgs = set([ + unreg_msgs = [ 'UNREGISTERED', 'TORRENT NOT FOUND', 'TORRENT IS NOT FOUND', @@ -480,14 +480,14 @@ class Qbt: 'RETITLED', 'TRUNCATED', 'TORRENT IS NOT AUTHORIZED FOR USE ON THIS TRACKER' - ]) - ignore_msgs = set([ + ] + ignore_msgs = [ 'YOU HAVE REACHED THE CLIENT LIMIT FOR THIS TORRENT', 'MISSING PASSKEY', 'MISSING INFO_HASH', 'PASSKEY IS INVALID', 'INVALID PASSKEY' - ]) + ] for torrent in self.torrentvalid: check_tags = util.get_list(torrent.tags) # Remove any error torrents Tags that are no longer unreachable. diff --git a/modules/util.py b/modules/util.py index 68be063..183b0a6 100644 --- a/modules/util.py +++ b/modules/util.py @@ -1,4 +1,4 @@ -import logging, os, shutil, traceback, time, signal, json, re +import logging, os, shutil, traceback, time, signal, json from logging.handlers import RotatingFileHandler from ruamel import yaml from pathlib import Path @@ -189,16 +189,16 @@ def add_dict_list(keys, value, dict_map): dict_map[key] = [value] -def list_in_text(text, search_list, all=False): - length = len(search_list) - num = 0 - pattern = re.compile(r'\b' - + r'\b|\b'.join(re.escape(x) for x in search_list) - + r'\b') - for t in set(pattern.findall(text)): - num += 1 - if not all: return True - if(num == length and all): return True +def list_in_text(text, search_list, match_all=False): + if isinstance(search_list, list): search_list = set(search_list) + contains = set([x for x in search_list if ' ' in x]) + exception = search_list - contains + if match_all: + if all(x == m for m in text.split(" ") for x in exception) or all(x in text for x in contains): + return True + else: + if any(x == m for m in text.split(" ") for x in exception) or any(x in text for x in contains): + return True return False