Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Commit ac88cd2

Browse files
committed
Fix "Error with time data"
Automatically and silently default to "None" when an invalid date is encountered. Resolves #70
1 parent ae2fc2e commit ac88cd2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

exitwp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ def gi(q, unicode_wrap=True, empty=False):
176176
'items': parse_items(),
177177
}
178178

179+
def format_date(date_text,date_format):
180+
try:
181+
return datetime.strptime(date_text, date_format)
182+
except ValueError:
183+
return datetime.strptime("1900-01-01 00:00:00", date_format)
179184

180185
def write_jekyll(data, target_format):
181186

@@ -292,8 +297,7 @@ def get_attachment_path(src, dir, dir_prefix='images'):
292297
'title': i['title'],
293298
'link': i['link'],
294299
'author': i['author'],
295-
'date': datetime.strptime(
296-
i['date'], '%Y-%m-%d %H:%M:%S').replace(tzinfo=UTC()),
300+
'date': format_date(i['date'], '%Y-%m-%d %H:%M:%S'),
297301
'slug': i['slug'],
298302
'wordpress_id': int(i['wp_id']),
299303
'comments': i['comments'],

0 commit comments

Comments
 (0)