Cleaner history suffix handling

pull/897/head
dgtlmoon 2 years ago
parent 687cf9beb4
commit f35d91e4fb

@ -1,6 +1,7 @@
class fetch_processor(): class fetch_processor():
contents = b'' contents = b''
screenshot = None screenshot = None
history_artifact_suffix = 'txt'
""" """
base class for all fetch processors base class for all fetch processors
@ -37,4 +38,4 @@ class fetch_processor():
if proxy_args is None: if proxy_args is None:
proxy_args = self.datastore.proxy_list[0][0] proxy_args = self.datastore.proxy_list[0][0]
return proxy_args return proxy_args

@ -148,9 +148,7 @@ class model(dict):
bump = self.history bump = self.history
return self.__newest_history_key return self.__newest_history_key
# Save some text file to the appropriate path and bump the history def save_history_artifact(self, contents: bytes, timestamp, suffix='txt'):
# result_obj from fetch_site_status.run()
def save_history_text(self, contents, timestamp):
import uuid import uuid
import logging import logging
@ -158,8 +156,8 @@ class model(dict):
self.ensure_data_dir_exists() self.ensure_data_dir_exists()
snapshot_fname = "{}/{}.stripped.txt".format(output_path, uuid.uuid4()) snapshot_fname = "{}/{}.{}".format(output_path, uuid.uuid4(), suffix)
logging.debug("Saving history text {}".format(snapshot_fname)) logging.debug("Saving history artifact {}".format(snapshot_fname))
with open(snapshot_fname, 'wb') as f: with open(snapshot_fname, 'wb') as f:
f.write(contents) f.write(contents)

@ -250,12 +250,11 @@ class update_worker(threading.Thread):
if process_changedetection_results: if process_changedetection_results:
try: try:
watch = self.datastore.data['watching'][uuid] watch = self.datastore.data['watching'][uuid]
fname = "" # Saved history text filename
# For the FIRST time we check a site, or a change detected, save the snapshot. # For the FIRST time we check a site, or a change detected, save the snapshot.
if changed_detected or not watch['last_checked']: if changed_detected or not watch['last_checked']:
# A change was detected # A change was detected
watch.save_history_text(contents=update_handler.contents, timestamp=str(round(time.time()))) watch.save_history_artifact(contents=update_handler.contents, timestamp=str(round(time.time())), suffix=update_handler.history_artifact_suffix)
self.datastore.update_watch(uuid=uuid, update_obj=update_obj) self.datastore.update_watch(uuid=uuid, update_obj=update_obj)

Loading…
Cancel
Save