diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 436f41018..08b3b5e49 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -850,14 +850,14 @@ def changedetection_app(config=None, datastore_o=None): # Read as binary and force decode as UTF-8 # Windows may fail decode in python if we just use 'r' mode (chardet decode exception) try: - newest_version_file_contents = watch.get_history_snapshot(history[dates[-1]]) + newest_version_file_contents = watch.get_history_snapshot(dates[-1]) except Exception as e: - newest_version_file_contents = "Unable to read {}.\n".format(history[dates[-1]]) + newest_version_file_contents = "Unable to read {}.\n".format(dates[-1]) previous_version = request.args.get('previous_version') - previous_timestamp = history[dates[-2]] + previous_timestamp = dates[-2] if previous_version: - previous_timestamp= previous_version + previous_timestamp = previous_version try: previous_version_file_contents = watch.get_history_snapshot(previous_timestamp) diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index 014e2c220..cf0494da5 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -241,6 +241,10 @@ class model(dict): bump = self.history return self.__newest_history_key + def get_history_snapshot(self, timestamp): + with open(self.history[timestamp], 'r', encoding='utf-8', errors='ignore') as f: + return f.read() + # Save some text file to the appropriate path and bump the history # result_obj from fetch_site_status.run() def save_history_text(self, contents, timestamp, snapshot_id): @@ -359,9 +363,6 @@ class model(dict): return fname return False - def get_history_snapshot(self, timestamp): - with open(self.history[timestamp], 'rb', encoding='utf-8', errors='ignore') as f: - return f.read() def pause(self): self['paused'] = True