diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 7362345a..d75f6a73 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -500,7 +500,7 @@ def changedetection_app(config=None, datastore_o=None): import hashlib - from changedetectionio.fetch_processor import json_html_plaintext + from .fetch_processor import json_html_plaintext # Get the most recent one newest_history_key = datastore.data['watching'][uuid].get('newest_history_key') diff --git a/changedetectionio/fetch_processor/__init__.py b/changedetectionio/fetch_processor/__init__.py index e69de29b..5f41fae9 100644 --- a/changedetectionio/fetch_processor/__init__.py +++ b/changedetectionio/fetch_processor/__init__.py @@ -0,0 +1,37 @@ +class fetch_processor(): + """ + 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 \ No newline at end of file diff --git a/changedetectionio/fetch_processor/fetch_processor.py b/changedetectionio/fetch_processor/fetch_processor.py deleted file mode 100644 index 5f41fae9..00000000 --- a/changedetectionio/fetch_processor/fetch_processor.py +++ /dev/null @@ -1,37 +0,0 @@ -class fetch_processor(): - """ - 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 \ No newline at end of file diff --git a/changedetectionio/fetch_processor/json_html_plaintext.py b/changedetectionio/fetch_processor/json_html_plaintext.py index e5240c01..8be2fdca 100644 --- a/changedetectionio/fetch_processor/json_html_plaintext.py +++ b/changedetectionio/fetch_processor/json_html_plaintext.py @@ -9,7 +9,7 @@ from changedetectionio import content_fetcher, html_tools urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) -from .fetch_processor import fetch_processor +from . import fetch_processor # Some common stuff here that can be moved to a base class # (set_proxy_from_list) diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index 8fdcd194..dab591a8 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -117,7 +117,7 @@ class update_worker(threading.Thread): os.unlink(full_path) def run(self): - from changedetectionio.fetch_processor import json_html_plaintext + from .fetch_processor import json_html_plaintext update_handler = json_html_plaintext.perform_site_check(datastore=self.datastore)