|
|
@ -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,37 +68,55 @@ 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
|
|
|
|
n_object = {
|
|
|
|
dates = [int(i) for i in dates]
|
|
|
|
'watch_url': watch['url'],
|
|
|
|
dates.sort(reverse=True)
|
|
|
|
'uuid': uuid,
|
|
|
|
dates = [str(i) for i in dates]
|
|
|
|
'current_snapshot': newest_version_file_contents
|
|
|
|
|
|
|
|
}
|
|
|
|
prev_fname = watch['history'][dates[1]]
|
|
|
|
|
|
|
|
|
|
|
|
# Did it have any notification alerts to hit?
|
|
|
|
|
|
|
|
if len(watch['notification_urls']):
|
|
|
|
# Did it have any notification alerts to hit?
|
|
|
|
print(">>> Notifications queued for UUID from watch {}".format(uuid))
|
|
|
|
if len(watch['notification_urls']):
|
|
|
|
n_object['notification_urls'] = watch['notification_urls']
|
|
|
|
print(">>> Notifications queued for UUID from watch {}".format(uuid))
|
|
|
|
n_object['notification_title'] = watch['notification_title']
|
|
|
|
n_object['notification_urls'] = watch['notification_urls']
|
|
|
|
n_object['notification_body'] = watch['notification_body']
|
|
|
|
n_object['notification_title'] = watch['notification_title']
|
|
|
|
n_object['notification_format'] = watch['notification_format']
|
|
|
|
n_object['notification_body'] = watch['notification_body']
|
|
|
|
self.notification_q.put(n_object)
|
|
|
|
n_object['notification_format'] = watch['notification_format']
|
|
|
|
|
|
|
|
|
|
|
|
# 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']):
|
|
|
|
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(uuid))
|
|
|
|
n_object['notification_urls'] = self.datastore.data['settings']['application']['notification_urls']
|
|
|
|
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_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)
|
|
|
|