diff --git a/changedetectionio/fetch_processor/__init__.py b/changedetectionio/fetch_processor/__init__.py index 9c82cb9b..a8999a2d 100644 --- a/changedetectionio/fetch_processor/__init__.py +++ b/changedetectionio/fetch_processor/__init__.py @@ -3,40 +3,10 @@ available_fetchers = [('json_html_plaintext', 'JSON/HTML/Text'), ('image', 'Grap class fetch_processor(): contents = b'' screenshot = None + datastore = None """ base class for all fetch processors - json_html_plaintext - image (future) """ - def __init__(self, *args, datastore, **kwargs): - super().__init__(*args, **kwargs) - self.datastore = datastore - - # If there was a proxy list enabled, figure out what proxy_args/which proxy to use - # if watch.proxy use that - # fetcher.proxy_override = watch.proxy or main config proxy - # Allows override the proxy on a per-request basis - # ALWAYS use the first one is nothing selected - - def set_proxy_from_list(self, watch): - proxy_args = None - if self.datastore.proxy_list is None: - return None - - # If its a valid one - if any([watch['proxy'] in p for p in self.datastore.proxy_list]): - proxy_args = watch['proxy'] - - # not valid (including None), try the system one - else: - system_proxy = self.datastore.data['settings']['requests']['proxy'] - # Is not None and exists - if any([system_proxy in p for p in self.datastore.proxy_list]): - proxy_args = system_proxy - - # Fallback - Did not resolve anything, use the first available - if proxy_args is None: - proxy_args = self.datastore.proxy_list[0][0] - - return proxy_args diff --git a/changedetectionio/fetch_processor/image.py b/changedetectionio/fetch_processor/image.py index 32c0a106..861477b8 100644 --- a/changedetectionio/fetch_processor/image.py +++ b/changedetectionio/fetch_processor/image.py @@ -27,6 +27,10 @@ from . import fetch_processor class perform_site_check(fetch_processor): xpath_data = None + def __init__(self, *args, datastore, **kwargs): + self.datastore = datastore + super().__init__(*args, **kwargs) + def run(self, uuid): changed_detected = False screenshot = False # as bytes @@ -74,7 +78,7 @@ class perform_site_check(fetch_processor): # If the klass doesnt exist, just use a default klass = getattr(content_fetcher, "html_requests") - proxy_args = self.set_proxy_from_list(watch) + proxy_args = self.datastore.get_preferred_proxy_for_watch(uuid) fetcher = klass(proxy_override=proxy_args) fetcher.run( diff --git a/changedetectionio/fetch_processor/json_html_plaintext.py b/changedetectionio/fetch_processor/json_html_plaintext.py index cc4b9707..4fddbc02 100644 --- a/changedetectionio/fetch_processor/json_html_plaintext.py +++ b/changedetectionio/fetch_processor/json_html_plaintext.py @@ -18,8 +18,9 @@ class perform_site_check(fetch_processor): xpath_data = None def __init__(self, *args, datastore, **kwargs): - super().__init__(*args, **kwargs) self.datastore = datastore + super().__init__(*args, **kwargs) + # Doesn't look like python supports forward slash auto enclosure in re.findall # So convert it to inline flag "foobar(?i)" type configuration