From 750b882546fd74e0ff34e865322ea33450ae3adf Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 22 Jul 2021 10:32:42 +1000 Subject: [PATCH] Re #149 - allow empty timestamp limit for scrub operation --- backend/__init__.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index a6439968..a85123eb 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -299,25 +299,28 @@ def changedetection_app(config=None, datastore_o=None): if request.method == 'POST': confirmtext = request.form.get('confirmtext') limit_date = request.form.get('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('(\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') + 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('(\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')) - 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():