From 256aeee5d501fbea36d63ea816f12a192c4b908e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 10 Jun 2020 18:39:33 -0700 Subject: [PATCH] Add epub.get_dates and add "(Year)" to the headerfile template. --- epubfile.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/epubfile.py b/epubfile.py index 09f6a29..150cdaa 100644 --- a/epubfile.py +++ b/epubfile.py @@ -898,6 +898,11 @@ class Epub: creators = [str(c.contents[0]) for c in creators if len(c.contents) == 1] return creators + def get_dates(self): + dates = self.opf.metadata.find_all({'dc:date'}) + dates = [str(t.contents[0]) for t in dates if len(t.contents) == 1] + return dates + def get_languages(self): languages = self.opf.metadata.find_all({'dc:language'}) languages = [str(l.contents[0]) for l in languages if len(l.contents) == 1] @@ -1603,8 +1608,17 @@ def merge( title = input_book.get_titles()[0] except IndexError: title = input_filepath.replace_extension('').basename + + try: + year = input_book.get_dates()[0] + except IndexError: + pass + else: + title = f'{title} ({year})' + if number_headerfile: title = f'{index:>0{index_length}}. {title}' + content += f'

{html.escape(title)}

' try: