diff --git a/ofscraper/models/selector.py b/ofscraper/models/selector.py index 2d08b8729..8d3911488 100644 --- a/ofscraper/models/selector.py +++ b/ofscraper/models/selector.py @@ -167,12 +167,7 @@ def filterNSort(): usernames = ALL_SUBS log.debug(f"username count no filters: {len(usernames)}") - filterusername = subtype.subType(usernames) - filterusername = price.pricePaidFreeFilterHelper(filterusername) - filterusername = flags.promoFilterHelper(filterusername) - filterusername = date_.dateFilters(filterusername) - filterusername = other.otherFilters(filterusername) - + filterusername = filterOnly(usernames) log.debug(f"final username count with all filters: {len(filterusername)}") # give log time to process time.sleep(constants.getattr("LOG_DISPLAY_TIMEOUT")) @@ -199,3 +194,13 @@ def filterNSort(): ) setfilter(forced=True) + + +def filterOnly(usernames=None): + usernames = usernames or ALL_SUBS + filterusername = subtype.subType(usernames) + filterusername = price.pricePaidFreeFilterHelper(filterusername) + filterusername = flags.promoFilterHelper(filterusername) + filterusername = date_.dateFilters(filterusername) + filterusername = other.otherFilters(filterusername) + return filterusername diff --git a/ofscraper/prompts/helpers/prompt_helpers.py b/ofscraper/prompts/helpers/prompt_helpers.py index 198a77731..3c83d9837 100644 --- a/ofscraper/prompts/helpers/prompt_helpers.py +++ b/ofscraper/prompts/helpers/prompt_helpers.py @@ -1,4 +1,3 @@ -import copy import inspect import re @@ -10,6 +9,7 @@ import ofscraper.prompts.prompt_strings as prompt_strings import ofscraper.utils.args.read as read_args import ofscraper.utils.config.data as config_data +import ofscraper.utils.context.stdout as stdout import ofscraper.utils.settings as settings console = Console() @@ -114,29 +114,30 @@ def sort_info(prompt_): def model_funct(prompt): userselector.setfilter() - models = userselector.parsed_subscriptions_helper() - choices = list( - map( - lambda x: modelHelpers.model_selectorHelper(x[0], x[1]), - enumerate(models), + with stdout.nostdout(): + models = userselector.filterOnly() + choices = list( + map( + lambda x: modelHelpers.model_selectorHelper(x[0], x[1]), + enumerate(models), + ) ) - ) - selectedSet = set( - map( - lambda x: re.search("^[0-9]+: ([^ ]+)", x["name"]).group(1), - prompt.selected_choices or [], + selectedSet = set( + map( + lambda x: re.search("^[0-9]+: ([^ ]+)", x["name"]).group(1), + prompt.selected_choices or [], + ) ) - ) - for model in choices: - name = re.search("^[0-9]+: ([^ ]+)", model.name).group(1) - if name in selectedSet: - model.enabled = True - prompt.content_control._raw_choices = choices - prompt.content_control.choices = prompt.content_control._get_choices( - prompt.content_control._raw_choices, prompt.content_control._default - ) - prompt.content_control._format_choices() - return prompt + for model in choices: + name = re.search("^[0-9]+: ([^ ]+)", model.name).group(1) + if name in selectedSet: + model.enabled = True + prompt.content_control._raw_choices = choices + prompt.content_control.choices = prompt.content_control._get_choices( + prompt.content_control._raw_choices, prompt.content_control._default + ) + prompt.content_control._format_choices() + return prompt def user_list(model_str): diff --git a/ofscraper/utils/context/stdout.py b/ofscraper/utils/context/stdout.py index 20c3480cc..465833fab 100644 --- a/ofscraper/utils/context/stdout.py +++ b/ofscraper/utils/context/stdout.py @@ -35,7 +35,12 @@ def lowstdout(): @contextlib.contextmanager def nostdout(): - save_stdout = sys.stdout - sys.stdout = io.BytesIO() - yield - sys.stdout = save_stdout + try: + save_stdout = sys.stdout + sys.stdout = open(os.devnull, "w") + yield + sys.stdout = save_stdout + except: + None + yield + None diff --git a/pyproject.toml b/pyproject.toml index 1ab16eb7c..9e6a93a9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,6 @@ pywidevine = "^1.8.0" aioprocessing = "^2.0.1" more-itertools = "^10.2.0" psutil = "^5.9.8" -pytest = "^7.4.0" humanfriendly = "^10.0" filelock = "^3.13.1" aiofiles = "^23.2.1"