pull/791/head
dgtlmoon 2 years ago
parent 8e9e32eaef
commit 5aee457b4d

@ -21,9 +21,12 @@ class update_worker(threading.Thread):
self.datastore = datastore
super().__init__(*args, **kwargs)
def send_content_changed_notification(self, uuid):
def send_content_changed_notification(self, t, watch_uuid):
from changedetectionio import diff
n_object = {}
watch = self.datastore.data['watching'].get(uuid, False)
watch = self.datastore.data['watching'].get(watch_uuid, False)
if not watch:
return
@ -38,7 +41,7 @@ class update_worker(threading.Thread):
# Did it have any notification alerts to hit?
if len(watch['notification_urls']):
print(">>> Notifications queued for UUID from watch {}".format(uuid))
print(">>> Notifications queued for UUID from watch {}".format(watch_uuid))
n_object['notification_urls'] = watch['notification_urls']
n_object['notification_title'] = watch['notification_title']
n_object['notification_body'] = watch['notification_body']
@ -46,7 +49,7 @@ class update_worker(threading.Thread):
# No? maybe theres a global setting, queue them all
elif len(self.datastore.data['settings']['application']['notification_urls']):
print(">>> Watch notification URLs were empty, using GLOBAL notifications for UUID: {}".format(uuid))
print(">>> Watch notification URLs were empty, using GLOBAL notifications for UUID: {}".format(watch_uuid))
n_object['notification_urls'] = self.datastore.data['settings']['application']['notification_urls']
n_object['notification_title'] = self.datastore.data['settings']['application']['notification_title']
n_object['notification_body'] = self.datastore.data['settings']['application']['notification_body']
@ -62,15 +65,13 @@ class update_worker(threading.Thread):
else:
line_feed_sep = "\n"
from changedetectionio import diff
snapshot_contents = ''
with open(watch_history[dates[-1]], 'rb') as f:
snapshot_contents = f.read()
n_object.update({
'watch_url': watch['url'],
'uuid': uuid,
'uuid': watch_uuid,
'current_snapshot': snapshot_contents.decode('utf-8'),
'diff': diff.render_diff(watch_history[dates[-2]], watch_history[dates[-1]], line_feed_sep=line_feed_sep),
'diff_full': diff.render_diff(watch_history[dates[-2]], watch_history[dates[-1]], True, line_feed_sep=line_feed_sep)
@ -78,10 +79,10 @@ class update_worker(threading.Thread):
self.notification_q.put(n_object)
def send_filter_failure_notification(self, uuid):
def send_filter_failure_notification(self, watch_uuid):
threshold = self.datastore.data['settings']['application'].get('filter_failure_notification_threshold_attempts')
watch = self.datastore.data['watching'].get(uuid, False)
watch = self.datastore.data['watching'].get(watch_uuid, False)
n_object = {'notification_title': 'Changedetection.io - Alert - CSS/xPath filter was not present in the page',
'notification_body': "Your configured CSS/xPath filter of '{}' for {{watch_url}} did not appear on the page after {} attempts, did the page change layout?\n\nLink: {{base_url}}/edit/{{watch_uuid}}\n\nThanks - Your omniscient changedetection.io installation :)\n".format(
@ -99,10 +100,10 @@ class update_worker(threading.Thread):
if 'notification_urls' in n_object:
n_object.update({
'watch_url': watch['url'],
'uuid': uuid
'uuid': watch_uuid
})
self.notification_q.put(n_object)
print("Sent filter not found notification for {}".format(uuid))
print("Sent filter not found notification for {}".format(watch_uuid))
def run(self):
from changedetectionio import fetch_site_status
@ -215,7 +216,7 @@ class update_worker(threading.Thread):
# Atleast 2, means there really was a change
self.datastore.update_watch(uuid=uuid, update_obj={'last_changed': round(now)})
if not self.datastore.data['watching'][uuid].get('notification_muted'):
self.send_content_changed_notification(self, uuid)
self.send_content_changed_notification(self, watch_uuid=uuid)
except Exception as e:

Loading…
Cancel
Save