tweaks for merge

This commit is contained in:
dgtlmoon
2022-09-19 14:24:40 +02:00
parent d23a39a7d8
commit bb03879aad
3 changed files with 8 additions and 33 deletions
+1 -31
View File
@@ -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
+5 -1
View File
@@ -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(
@@ -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