-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_dummy_epub.py
More file actions
50 lines (48 loc) · 1.86 KB
/
create_dummy_epub.py
File metadata and controls
50 lines (48 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import zipfile
def create_epub(filename):
with zipfile.ZipFile(filename, 'w') as zf:
zf.writestr('mimetype', 'application/epub+zip', compress_type=zipfile.ZIP_STORED)
zf.writestr('META-INF/container.xml', '''<?xml version="1.0"?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="content.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>''')
zf.writestr('content.opf', '''<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookID" version="2.0">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:title>Snoopy's Guide to Life</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="BookID" opf:scheme="UUID">urn:uuid:12345</dc:identifier>
<dc:creator>Charles M. Schulz</dc:creator>
</metadata>
<manifest>
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
<item id="page1" href="page1.html" media-type="application/xhtml+xml"/>
</manifest>
<spine toc="ncx">
<itemref idref="page1"/>
</spine>
</package>''')
zf.writestr('toc.ncx', '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
<head>
</head>
<docTitle>
<text>Snoopy's Guide</text>
</docTitle>
<navMap>
<navPoint id="navPoint-1" playOrder="1">
<navLabel>
<text>Start</text>
</navLabel>
<content src="page1.html"/>
</navPoint>
</navMap>
</ncx>''')
zf.writestr('page1.html', '<html><body><h1>Hello Snoopy!</h1></body></html>')
if __name__ == "__main__":
create_epub("dummy.epub")
print("Created dummy.epub")