From ac88cd225fdb35ce7faf239255a3c62bf6e565ec Mon Sep 17 00:00:00 2001 From: ILAsoft Date: Fri, 6 Oct 2017 00:29:53 -0700 Subject: [PATCH] Fix "Error with time data" Automatically and silently default to "None" when an invalid date is encountered. Resolves https://github.com/thomasf/exitwp/issues/70 --- exitwp.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exitwp.py b/exitwp.py index 0a59010..c24e0cc 100755 --- a/exitwp.py +++ b/exitwp.py @@ -176,6 +176,11 @@ def gi(q, unicode_wrap=True, empty=False): 'items': parse_items(), } +def format_date(date_text,date_format): + try: + return datetime.strptime(date_text, date_format) + except ValueError: + return datetime.strptime("1900-01-01 00:00:00", date_format) def write_jekyll(data, target_format): @@ -292,8 +297,7 @@ def get_attachment_path(src, dir, dir_prefix='images'): 'title': i['title'], 'link': i['link'], 'author': i['author'], - 'date': datetime.strptime( - i['date'], '%Y-%m-%d %H:%M:%S').replace(tzinfo=UTC()), + 'date': format_date(i['date'], '%Y-%m-%d %H:%M:%S'), 'slug': i['slug'], 'wordpress_id': int(i['wp_id']), 'comments': i['comments'],