-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFORMATtoHTML.py
54 lines (51 loc) · 1.52 KB
/
FORMATtoHTML.py
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
51
52
53
54
import os
def tohtml(aPathList,contentList,savePath,bookName):
countfile = 0
manifest = []
spine = []
CODE = open("template/code.Template")
CODEtemp = CODE.readlines()
CODE.close()
CODEhead = CODEtemp[0:8]
CODEback = CODEtemp[8:]
for cname in aPathList:
if cname[-1:] == "/":
filename = contentList[countfile]
filename = filename[0:-1]+".html"
manifest.append('<item id="chap'+str(countfile)+'" href="'+filename+'" media-type="text/html"/>\n')
spine.append('<itemref idref="chap'+str(countfile)+'"/>\n')
wfile = open(savePath+filename,"w")
wfile.writelines(CODEhead)
wfile.write("<h3>"+filename[0:-5]+"</h3>/n")
wfile.writelines(CODEback)
wfile.close()
countfile+=1
continue
else:
filename = contentList[countfile]+".html"
manifest.append('<item id="chap'+str(countfile)+'" href="'+filename+'" media-type="text/html"/>\n')
spine.append('<itemref idref="chap'+str(countfile)+'"/>\n')
cfile = open(cname,"r")
ws = cfile.readlines()
wfile = open(savePath+filename,"w")
wfile.writelines(CODEhead)
wfile.writelines(ws)
wfile.writelines(CODEback)
cfile.close()
wfile.close()
countfile+=1
OPF = open("template/opf.Template")
OPFtemp = OPF.readlines()
OPF.close()
OPFhead1 = OPFtemp[0:6]
OPFhead2 = OPFtemp[6:26]
OPFmid = OPFtemp[27:29]
OPFback = OPFtemp[30:]
opf = open(savePath+"content.opf","w")
opf.writelines(OPFhead1)
opf.write(bookName)
opf.writelines(OPFhead2)
opf.writelines(manifest)
opf.writelines(OPFmid)
opf.writelines(spine)
opf.writelines(OPFback)