From 7d22d2ec25c626ff45ed5c68bbcceb2e245bc4d3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 9 Jan 2021 10:23:05 +0000 Subject: [PATCH] Handle exception on date format --- utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 0187f86ef..3ae51d9fa 100644 --- a/utils.py +++ b/utils.py @@ -47,8 +47,12 @@ def validPostDate(published: str, maxAgeDays=7) -> bool: daysDiff = datetime.datetime.utcnow() - baselineTime nowDaysSinceEpoch = daysDiff.days - postTimeObject = \ - datetime.datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ") + try: + postTimeObject = \ + datetime.datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ") + except BaseException: + return False + daysDiff = postTimeObject - baselineTime postDaysSinceEpoch = daysDiff.days