Skip to content

Commit

Permalink
Merge pull request #262 from cary-rowen/dateParsing
Browse files Browse the repository at this point in the history
fix(epub): ensure date parsing handles non-string inputs gracefully
  • Loading branch information
cary-rowen authored Aug 28, 2024
2 parents fbd2572 + b162d36 commit 4114fa6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bookworm/document/formats/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ def metadata(self):
desc = HTMLParser(info.get("description", "")).text()
except:
desc = None
date_value = info.get("date", "")
if not isinstance(date_value, str):
log.warning(f"Unexpected date format: {type(date_value)}. Converting to string.")
if isinstance(date_value, (int, float)):
date_value = str(date_value)
else:
date_value = ""
if pubdate := dateparser.parse(
info.get("date", ""),
date_value,
languages=[
self.language.two_letter_language_code,
],
Expand All @@ -92,7 +99,7 @@ def metadata(self):
pubdate, date_only=True, format="long", localized=True
)
else:
publish_date = ""
publish_date = "Unknown Publication Date"
return BookMetadata(
title=self.epub.title,
author=author.removeprefix("By ").strip(),
Expand Down

0 comments on commit 4114fa6

Please sign in to comment.