epub zip is now produced correctly, also TOC works with Stanza now

This commit is contained in:
sigizmund 2009-12-17 13:37:13 +00:00
parent d2d183430d
commit f55e6d3c05
3 changed files with 12 additions and 6 deletions

View file

@ -41,7 +41,7 @@ CONTENT_START = '''<?xml version="1.0"?>
<dc:identifier id="BookId">urn:uuid:sigizmund.com062820072147132</dc:identifier>
</metadata>
<manifest>
<item id="ncx" href="toc.ncx" media-type="text/xml" />
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
<item id="style" href="stylesheet.css" media-type="text/css" />
'''

View file

@ -69,6 +69,8 @@ class EPubFanficWriter(FanficWriter):
v = entities[e]
text = text.replace(e, v)
text = text.replace('&', '&amp;')
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'

View file

@ -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')