From be1dc2d39c74048f88f33a0ccc466d5ce34bb5e3 Mon Sep 17 00:00:00 2001 From: Francesco Grazioso <40018163+FrancescoGrazioso@users.noreply.github.com> Date: Sat, 22 Feb 2025 16:12:22 +0100 Subject: [PATCH] FEAT: add search capability from script args (#270) * add base run script and fix path for raspberry * Add support for passing search terms to functions Extend `run_function` to accept a `search_terms` parameter, allowing search filters to be dynamically passed. Update CLI argument parsing to include a `--search` option and propagate the value to the corresponding functions. * reset edits for local server --- StreamingCommunity/run.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/StreamingCommunity/run.py b/StreamingCommunity/run.py index 9cc5f42..d84c769 100644 --- a/StreamingCommunity/run.py +++ b/StreamingCommunity/run.py @@ -33,19 +33,20 @@ TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot') -def run_function(func: Callable[..., None], close_console: bool = False) -> None: +def run_function(func: Callable[..., None], close_console: bool = False, search_terms: str = None) -> None: """ Run a given function indefinitely or once, depending on the value of close_console. Parameters: func (Callable[..., None]): The function to run. close_console (bool, optional): Whether to close the console after running the function once. Defaults to False. + search_terms (str, optional): Search terms to use for the function. Defaults to None. """ if close_console: while 1: - func() + func(search_terms) else: - func() + func(search_terms) def load_search_functions(): @@ -249,9 +250,11 @@ def main(script_id = 0): long_option = alias parser.add_argument(f'-{short_option}', f'--{long_option}', action='store_true', help=f'Search for {alias.split("_")[0]} on streaming platforms.') + parser.add_argument('-s', '--search', default=None, help='Search terms') # Parse command-line arguments args = parser.parse_args() + search_terms = args.search # Map command-line arguments to the config values config_updates = {} @@ -283,7 +286,7 @@ def main(script_id = 0): # Check which argument is provided and run the corresponding function for arg, func in arg_to_function.items(): if getattr(args, arg): - run_function(func) + run_function(func, search_terms=search_terms) return # Mapping user input to functions @@ -336,7 +339,7 @@ def main(script_id = 0): # Run the corresponding function based on user input if category in input_to_function: - run_function(input_to_function[category]) + run_function(input_to_function[category], search_terms = args.search) else: if TELEGRAM_BOT: