Commits

Nikolaj Sjujskij committed b577e88

Add author (creator) to metadata

Comments (0)

Files changed (4)

rst2epub/converter.py

 def main():
     rst = RstDocument(sys.argv[1])
     title = rst.get_title()
+    author = rst.get_author()
     identifier = "TODO"
     language = "en_TODO"
-    writer = EpubWriter(sys.argv[2], title, identifier, language)
+    writer = EpubWriter(sys.argv[2], title, identifier, language, author)
 
     writer.container.add_rootfile(Package.path, Package.media_type)
 
     extension = ".epub"
     """EPUB file extension see 3.4 in OCF1.0"""
 
-    def __init__(self, to_file, title, identifier, language):
+    def __init__(self, to_file, title, identifier, language, author):
         self.to_file = to_file
         self.title = title
         self.identifier = identifier
         self.language = language
+        self.author = author
 
         # create the zip container with correct mimetype
         self.file = ZipFile(to_file, "w", ZIP_STORED)
 
         # ...add required metadata fields
         self.package.metadata.add_title(self.title)
+        self.package.metadata.add_creator(self.author)
         self.package.metadata.add_identifier(self.identifier, True)
         self.package.metadata.add_language(self.language)
 

rst2epub/package.py

         """See 2.2.1 in [OPF20]_."""
         self._create_dc_metadata_element("title", title)
 
-    def add_creator(self):
+    def add_creator(self, author):
         """See 2.2.2 in [OPF20]_."""
-        raise NotImplementedError
+        self._create_dc_metadata_element("creator", author)
 
     def add_subject(self):
         """See 2.2.3 in [OPF20]_."""
             if element.findtext("./field_name") == field_name:
                 return element.findtext(path_to_value)
 
-    # def get_author(self):
-        # return self._get_field_value("Author", "./field_body//*")
+    def get_author(self):
+        return self._get_field_value("Author", "./field_body//*")
 
     # def get_contact(self):
         # return self._get_field_value("Contact", "./field_body/paragraph//*")