Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Fix "Error with time data"
Browse files Browse the repository at this point in the history
Automatically and silently default to "None" when an invalid date is encountered.
Resolves some-programs#70
  • Loading branch information
ILAsoft committed Oct 6, 2017
1 parent ae2fc2e commit ac88cd2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions exitwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit ac88cd2

Please sign in to comment.