|
|
@ -56,9 +56,8 @@ class update_worker(threading.Thread):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.datastore.update_watch(uuid=uuid, update_obj=update_obj)
|
|
|
|
self.datastore.update_watch(uuid=uuid, update_obj=update_obj)
|
|
|
|
if changed_detected:
|
|
|
|
if changed_detected:
|
|
|
|
|
|
|
|
n_object = {}
|
|
|
|
# A change was detected
|
|
|
|
# A change was detected
|
|
|
|
newest_version_file_contents = ""
|
|
|
|
|
|
|
|
fname = self.datastore.save_history_text(watch_uuid=uuid, contents=contents)
|
|
|
|
fname = self.datastore.save_history_text(watch_uuid=uuid, contents=contents)
|
|
|
|
|
|
|
|
|
|
|
|
# Update history with the stripped text for future reference, this will also mean we save the first
|
|
|
|
# Update history with the stripped text for future reference, this will also mean we save the first
|
|
|
@ -69,17 +68,18 @@ class update_worker(threading.Thread):
|
|
|
|
|
|
|
|
|
|
|
|
print (">> Change detected in UUID {} - {}".format(uuid, watch['url']))
|
|
|
|
print (">> Change detected in UUID {} - {}".format(uuid, watch['url']))
|
|
|
|
|
|
|
|
|
|
|
|
# Get the newest snapshot data to be possibily used in a notification
|
|
|
|
# Notifications should only trigger on the second time (first time, we gather the initial snapshot)
|
|
|
|
newest_key = self.datastore.get_newest_history_key(uuid)
|
|
|
|
if len(watch['history']) > 1:
|
|
|
|
if newest_key:
|
|
|
|
|
|
|
|
with open(watch['history'][newest_key], 'r') as f:
|
|
|
|
dates = list(watch['history'].keys())
|
|
|
|
newest_version_file_contents = f.read().strip()
|
|
|
|
# Convert to int, sort and back to str again
|
|
|
|
|
|
|
|
# @todo replace datastore getter that does this automatically
|
|
|
|
|
|
|
|
dates = [int(i) for i in dates]
|
|
|
|
|
|
|
|
dates.sort(reverse=True)
|
|
|
|
|
|
|
|
dates = [str(i) for i in dates]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prev_fname = watch['history'][dates[1]]
|
|
|
|
|
|
|
|
|
|
|
|
n_object = {
|
|
|
|
|
|
|
|
'watch_url': watch['url'],
|
|
|
|
|
|
|
|
'uuid': uuid,
|
|
|
|
|
|
|
|
'current_snapshot': newest_version_file_contents
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Did it have any notification alerts to hit?
|
|
|
|
# Did it have any notification alerts to hit?
|
|
|
|
if len(watch['notification_urls']):
|
|
|
|
if len(watch['notification_urls']):
|
|
|
@ -88,7 +88,6 @@ class update_worker(threading.Thread):
|
|
|
|
n_object['notification_title'] = watch['notification_title']
|
|
|
|
n_object['notification_title'] = watch['notification_title']
|
|
|
|
n_object['notification_body'] = watch['notification_body']
|
|
|
|
n_object['notification_body'] = watch['notification_body']
|
|
|
|
n_object['notification_format'] = watch['notification_format']
|
|
|
|
n_object['notification_format'] = watch['notification_format']
|
|
|
|
self.notification_q.put(n_object)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# No? maybe theres a global setting, queue them all
|
|
|
|
# No? maybe theres a global setting, queue them all
|
|
|
|
elif len(self.datastore.data['settings']['application']['notification_urls']):
|
|
|
|
elif len(self.datastore.data['settings']['application']['notification_urls']):
|
|
|
@ -97,10 +96,28 @@ class update_worker(threading.Thread):
|
|
|
|
n_object['notification_title'] = self.datastore.data['settings']['application']['notification_title']
|
|
|
|
n_object['notification_title'] = self.datastore.data['settings']['application']['notification_title']
|
|
|
|
n_object['notification_body'] = self.datastore.data['settings']['application']['notification_body']
|
|
|
|
n_object['notification_body'] = self.datastore.data['settings']['application']['notification_body']
|
|
|
|
n_object['notification_format'] = self.datastore.data['settings']['application']['notification_format']
|
|
|
|
n_object['notification_format'] = self.datastore.data['settings']['application']['notification_format']
|
|
|
|
self.notification_q.put(n_object)
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print(">>> NO notifications queued, watch and global notification URLs were empty.")
|
|
|
|
print(">>> NO notifications queued, watch and global notification URLs were empty.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Only prepare to notify if the rules above matched
|
|
|
|
|
|
|
|
if 'notification_urls' in n_object:
|
|
|
|
|
|
|
|
# HTML needs linebreak, but MarkDown and Text can use a linefeed
|
|
|
|
|
|
|
|
if n_object['notification_format'] == 'HTML':
|
|
|
|
|
|
|
|
line_feed_sep = "</br>"
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
line_feed_sep = "\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from changedetectionio import diff
|
|
|
|
|
|
|
|
n_object.update({
|
|
|
|
|
|
|
|
'watch_url': watch['url'],
|
|
|
|
|
|
|
|
'uuid': uuid,
|
|
|
|
|
|
|
|
'current_snapshot': str(contents),
|
|
|
|
|
|
|
|
'diff_full': diff.render_diff(prev_fname, fname, line_feed_sep=line_feed_sep),
|
|
|
|
|
|
|
|
'diff': diff.render_diff(prev_fname, fname, True, line_feed_sep=line_feed_sep)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.notification_q.put(n_object)
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
print("!!!! Exception in update_worker !!!\n", e)
|
|
|
|
print("!!!! Exception in update_worker !!!\n", e)
|
|
|
|
|
|
|
|
|
|
|
|