From f55e6d3c05be0a0e718213aad8ed18da2b18c224 Mon Sep 17 00:00:00 2001 From: sigizmund Date: Thu, 17 Dec 2009 13:37:13 +0000 Subject: [PATCH] epub zip is now produced correctly, also TOC works with Stanza now --- constants.py | 2 +- output.py | 10 ++++++++-- zipdir.py | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/constants.py b/constants.py index 6387cb70..27515658 100644 --- a/constants.py +++ b/constants.py @@ -41,7 +41,7 @@ CONTENT_START = ''' urn:uuid:sigizmund.com062820072147132 - + ''' diff --git a/output.py b/output.py index bd82a6e3..3159fe78 100644 --- a/output.py +++ b/output.py @@ -69,6 +69,8 @@ class EPubFanficWriter(FanficWriter): v = entities[e] text = text.replace(e, v) + text = text.replace('&', '&') + return text def writeChapter(self, title, text): @@ -100,9 +102,10 @@ class EPubFanficWriter(FanficWriter): # cleanup(self.soup ) text = self.soup.prettify() - print(text) - print >> f, XHTML_START % (title, title) + tt = self._removeEntities(title) + + print >> f, XHTML_START % (tt, tt) f.write(text) print >> f, XHTML_END @@ -147,6 +150,9 @@ class EPubFanficWriter(FanficWriter): print >> opf, CONTENT_END + opf.close() + toc.close() + print('Finished') filename = self.directory + '.epub' diff --git a/zipdir.py b/zipdir.py index cd9b493b..e5d596e7 100644 --- a/zipdir.py +++ b/zipdir.py @@ -21,7 +21,7 @@ def toZip(filename, directory): zippedHelp.close() def addFolderToZip(zippedHelp,folder,fpath): - print('addFolderToZip(%s)' % folder) + #print('addFolderToZip(%s)' % folder) if folder == '.' or folder == '..': return @@ -29,11 +29,11 @@ def addFolderToZip(zippedHelp,folder,fpath): folderFiles = os.listdir(fpath) for f in folderFiles: if os.path.isfile(fpath + '/' + f): - print('basename=%s' % os.path.basename(fpath + '/' + f)) + #print('basename=%s' % os.path.basename(fpath + '/' + f)) zippedHelp.write(fpath + '/' + f, folder + '/' + f, zipfile.ZIP_DEFLATED) elif os.path.isdir(f): addFolderToZip(zippedHelp,f) if __name__ == '__main__': - toZip('sample.epub', "books/Harry's_Second_Chance:_Back_From_the_Future") + toZip('sample.epub', "books/A_Time_To_Reflect") z = zipfile.ZipFile('sample.epub', 'r') \ No newline at end of file