Skip to content

Commit

Permalink
select only once
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Mar 22, 2024
1 parent 7c5b62c commit 6f88162
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
17 changes: 11 additions & 6 deletions ofscraper/models/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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
45 changes: 23 additions & 22 deletions ofscraper/prompts/helpers/prompt_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
import inspect
import re

Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 9 additions & 4 deletions ofscraper/utils/context/stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6f88162

Please sign in to comment.