diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 50c0d436..83599fa1 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -434,48 +434,21 @@ def changedetection_app(config=None, datastore_o=None): @login_required def scrub_page(): - import re - if request.method == 'POST': confirmtext = request.form.get('confirmtext') - limit_date = request.form.get('limit_date') - limit_timestamp = 0 - - # Re #149 - allow empty/0 timestamp limit - if len(limit_date): - try: - limit_date = limit_date.replace('T', ' ') - # I noticed chrome will show '/' but actually submit '-' - limit_date = limit_date.replace('-', '/') - # In the case that :ss seconds are supplied - limit_date = re.sub(r'(\d\d:\d\d)(:\d\d)', '\\1', limit_date) - - str_to_dt = datetime.datetime.strptime(limit_date, '%Y/%m/%d %H:%M') - limit_timestamp = int(str_to_dt.timestamp()) - - if limit_timestamp > time.time(): - flash("Timestamp is in the future, cannot continue.", 'error') - return redirect(url_for('scrub_page')) - - except ValueError: - flash('Incorrect date format, cannot continue.', 'error') - return redirect(url_for('scrub_page')) if confirmtext == 'scrub': changes_removed = 0 - for uuid, watch in datastore.data['watching'].items(): - if limit_timestamp: - changes_removed += datastore.scrub_watch(uuid, limit_timestamp=limit_timestamp) - else: - changes_removed += datastore.scrub_watch(uuid) + for uuid in datastore.data['watching'].keys(): + datastore.scrub_watch(uuid) - flash("Cleared snapshot history ({} snapshots removed)".format(changes_removed)) + flash("Cleared all snapshot history") else: flash('Incorrect confirmation text.', 'error') return redirect(url_for('index')) - output = render_template("scrub.html") + output = render_template("scrub.html") return output diff --git a/changedetectionio/store.py b/changedetectionio/store.py index 4380bd1e..ed4a915a 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -260,46 +260,14 @@ class ChangeDetectionStore: return self.data['watching'][uuid].get(val) # Remove a watchs data but keep the entry (URL etc) - def scrub_watch(self, uuid, limit_timestamp = False): - - import hashlib - del_timestamps = [] - - changes_removed = 0 - - for timestamp, path in self.data['watching'][uuid]['history'].items(): - if not limit_timestamp or (limit_timestamp is not False and int(timestamp) > limit_timestamp): - self.unlink_history_file(path) - del_timestamps.append(timestamp) - changes_removed += 1 - - if not limit_timestamp: - self.data['watching'][uuid]['last_checked'] = 0 - self.data['watching'][uuid]['last_changed'] = 0 - self.data['watching'][uuid]['previous_md5'] = "" - - - for timestamp in del_timestamps: - del self.data['watching'][uuid]['history'][str(timestamp)] - - # If there was a limitstamp, we need to reset some meta data about the entry - # This has to happen after we remove the others from the list - if limit_timestamp: - newest_key = self.get_newest_history_key(uuid) - if newest_key: - self.data['watching'][uuid]['last_checked'] = int(newest_key) - # @todo should be the original value if it was less than newest key - self.data['watching'][uuid]['last_changed'] = int(newest_key) - try: - with open(self.data['watching'][uuid]['history'][str(newest_key)], "rb") as fp: - content = fp.read() - self.data['watching'][uuid]['previous_md5'] = hashlib.md5(content).hexdigest() - except (FileNotFoundError, IOError): - self.data['watching'][uuid]['previous_md5'] = "" - pass + def scrub_watch(self, uuid): + import pathlib - self.needs_write = True - return changes_removed + self.__data['watching'][uuid].update({'history': {}, 'last_checked': 0, 'last_changed': 0, 'newest_history_key': 0, 'previous_md5': False}) + self.needs_write_urgent = True + + for item in pathlib.Path(self.datastore_path).rglob(uuid+"/*.txt"): + unlink(item) def add_watch(self, url, tag="", extras=None, write_to_disk_now=True): if extras is None: @@ -453,10 +421,11 @@ class ChangeDetectionStore: import pathlib # Only in the sub-directories - for item in pathlib.Path(self.datastore_path).rglob("*/*txt"): - if not str(item) in index: - print ("Removing",item) - unlink(item) + for uuid in self.data['watching']: + for item in pathlib.Path(self.datastore_path).rglob(uuid+"/*.txt"): + if not str(item) in index: + print ("Removing",item) + unlink(item) # Run all updates # IMPORTANT - Each update could be run even when they have a new install and the schema is correct diff --git a/changedetectionio/templates/scrub.html b/changedetectionio/templates/scrub.html index bd006b31..5b9a15da 100644 --- a/changedetectionio/templates/scrub.html +++ b/changedetectionio/templates/scrub.html @@ -7,7 +7,7 @@
- This will remove all version snapshots/data, but keep your list of URLs.
+ This will remove ALL version snapshots/data, but keep your list of URLs.
You may like to use the BACKUP link first.

@@ -17,12 +17,6 @@ Type in the word scrub to confirm that you understand!
-
- - - dd/mm/yyyy hh:mm (24 hour format) -
-