From 3651c2d43d890988533ca149dd3a591627996b41 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 18 Jun 2024 08:19:08 +0200 Subject: [PATCH 1/2] Prefer pythons built in "importlib" over pkg_resources+setuptools --- .../blueprint/browser_steps/browser_steps.py | 10 ++++------ changedetectionio/content_fetchers/base.py | 7 +++---- changedetectionio/content_fetchers/res/__init__.py | 1 + 3 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 changedetectionio/content_fetchers/res/__init__.py diff --git a/changedetectionio/blueprint/browser_steps/browser_steps.py b/changedetectionio/blueprint/browser_steps/browser_steps.py index 76f3d756159..c1112f5f696 100644 --- a/changedetectionio/blueprint/browser_steps/browser_steps.py +++ b/changedetectionio/blueprint/browser_steps/browser_steps.py @@ -255,8 +255,8 @@ def has_expired(self): def get_current_state(self): """Return the screenshot and interactive elements mapping, generally always called after action_()""" - from pkg_resources import resource_string - xpath_element_js = resource_string(__name__, "../../content_fetchers/res/xpath_element_scraper.js").decode('utf-8') + import importlib.resources + xpath_element_js = importlib.resources.read_text(__package__, "../../content_fetchers/res/xpath_element_scraper.js") now = time.time() self.page.wait_for_timeout(1 * 1000) @@ -287,11 +287,9 @@ def request_visualselector_data(self): :param current_include_filters: :return: """ - + import importlib.resources self.page.evaluate("var include_filters=''") - from pkg_resources import resource_string - # The code that scrapes elements and makes a list of elements/size/position to click on in the VisualSelector - xpath_element_js = resource_string(__name__, "../../content_fetchers/res/xpath_element_scraper.js").decode('utf-8') + xpath_element_js = importlib.resources.read_text("changedetectionio.content_fetchers.res", "xpath_element_scraper.js") from changedetectionio.content_fetchers import visualselector_xpath_selectors xpath_element_js = xpath_element_js.replace('%ELEMENTS%', visualselector_xpath_selectors) xpath_data = self.page.evaluate("async () => {" + xpath_element_js + "}") diff --git a/changedetectionio/content_fetchers/base.py b/changedetectionio/content_fetchers/base.py index 1ca6876eda7..136fe9e5b6c 100644 --- a/changedetectionio/content_fetchers/base.py +++ b/changedetectionio/content_fetchers/base.py @@ -64,10 +64,9 @@ class Fetcher(): render_extract_delay = 0 def __init__(self): - from pkg_resources import resource_string - # The code that scrapes elements and makes a list of elements/size/position to click on in the VisualSelector - self.xpath_element_js = resource_string(__name__, "res/xpath_element_scraper.js").decode('utf-8') - self.instock_data_js = resource_string(__name__, "res/stock-not-in-stock.js").decode('utf-8') + import importlib.resources + self.xpath_element_js = importlib.resources.read_text("changedetectionio.content_fetchers.res", 'xpath_element_scraper.js') + self.instock_data_js = importlib.resources.read_text("changedetectionio.content_fetchers.res", 'stock-not-in-stock.js') @abstractmethod def get_error(self): diff --git a/changedetectionio/content_fetchers/res/__init__.py b/changedetectionio/content_fetchers/res/__init__.py new file mode 100644 index 00000000000..b41a98a51be --- /dev/null +++ b/changedetectionio/content_fetchers/res/__init__.py @@ -0,0 +1 @@ +# resources for browser injection/scraping From 2b7dc5e85440969a64b49c3803aa67b596e3d08b Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 18 Jun 2024 08:22:08 +0200 Subject: [PATCH 2/2] woops --- changedetectionio/blueprint/browser_steps/browser_steps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changedetectionio/blueprint/browser_steps/browser_steps.py b/changedetectionio/blueprint/browser_steps/browser_steps.py index c1112f5f696..ea7c099faef 100644 --- a/changedetectionio/blueprint/browser_steps/browser_steps.py +++ b/changedetectionio/blueprint/browser_steps/browser_steps.py @@ -256,7 +256,7 @@ def has_expired(self): def get_current_state(self): """Return the screenshot and interactive elements mapping, generally always called after action_()""" import importlib.resources - xpath_element_js = importlib.resources.read_text(__package__, "../../content_fetchers/res/xpath_element_scraper.js") + xpath_element_js = importlib.resources.read_text("changedetectionio.content_fetchers.res", "xpath_element_scraper.js") now = time.time() self.page.wait_for_timeout(1 * 1000)