From 9ebf96ea77e695f737c40a2b4a207985883a9161 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 28 Oct 2023 13:04:04 +0200 Subject: [PATCH] dont init steps unless there are valid steps --- changedetectionio/content_fetcher.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/changedetectionio/content_fetcher.py b/changedetectionio/content_fetcher.py index c3b4971c..60429556 100644 --- a/changedetectionio/content_fetcher.py +++ b/changedetectionio/content_fetcher.py @@ -159,6 +159,16 @@ class Fetcher(): """ return {k.lower(): v for k, v in self.headers.items()} + def browser_steps_get_valid_steps(self): + if self.browser_steps is not None and len(self.browser_steps): + valid_steps = filter( + lambda s: (s['operation'] and len(s['operation']) and s['operation'] != 'Choose one' and s['operation'] != 'Goto site'), + self.browser_steps) + + return valid_steps + + return None + def iterate_browser_steps(self): from changedetectionio.blueprint.browser_steps.browser_steps import steppable_browser_interface from playwright._impl._api_types import TimeoutError @@ -170,10 +180,7 @@ class Fetcher(): if self.browser_steps is not None and len(self.browser_steps): interface = steppable_browser_interface() interface.page = self.page - - valid_steps = filter( - lambda s: (s['operation'] and len(s['operation']) and s['operation'] != 'Choose one' and s['operation'] != 'Goto site'), - self.browser_steps) + valid_steps = self.browser_steps_get_valid_steps() for step in valid_steps: step_n += 1 @@ -511,7 +518,9 @@ class base_html_playwright(Fetcher): raise EmptyReply(url=url, status_code=response.status) # Run Browser Steps here - self.iterate_browser_steps() + if self.browser_steps_get_valid_steps(): + self.iterate_browser_steps() + gi self.page.wait_for_timeout(extra_wait * 1000) # So we can find an element on the page where its selector was entered manually (maybe not xPath etc)