アットウィキロゴ

toshooo

import zipfile
import os
import uuid 
 
def writez(nnx):
 
    zipFile = zipfile.ZipFile(nnx, 'w', zipfile.ZIP_STORED)
    zipFile.write('epub/mimetype','mimetype')
    zipFile.write('epub/META-INF/container.xml','META-INF/container.xml')
    zipFile.write('epub/item/style/book-style.css','item/style/book-style.css')
    zipFile.write('epub/item/style/style-standard.css','item/style/stylestyle-standard.css')
    zipFile.write('epub/item/style/fixed-layout-jp.css','item/style/fixed-layout-jp.css')
    zipFile.write('epub/item/style/style-advance.css','item/style/style-advance.css')
    zipFile.write('epub/item/style/style-check.css','item/style/style-checke.css')
    zipFile.write('epub/item/style/style-reset.css','item/style/style-reset.css')
    zipFile.write('epub/item/xhtml/p-caution.xhtml','item/xhtml/p-caution.xhtml')
    zipFile.write('epub/item/xhtml/p-cover.xhtml','item/xhtml/p-cover.xhtml')
    zipFile.write('epub/item/image/cover.jpg','item/image/cover.jpg')
    zipFile.write('p-titlepage.xhtml','item/xhtml/p-titlepage.xhtml')
    zipFile.write('p-colophon.xhtml','item/xhtml/p-colophon.xhtml')
    zipFile.write('p-toc.xhtml','item/xhtml/p-toc.xhtml')
    zipFile.write('standard.opf','item/standard.opf')
    for pp in page:
        zipFile.write(pp,"item/xhtml/"+pp)
 
    zipFile.close()
 
 
 
def filex():
 
    f4=open("epub/item/xhtml/memo.xhtml","r",encoding="UTF-8")
    x4=[]
    for line in f4:
        x4.append(line)
    f4.close() 
 
    n=0
    for t in txt:
 
        f5=open("file/"+t,"r",encoding="UTF-8")
        sig=""
        for line in f5:
            line=line.replace("\n","")
            sig=sig+"<p>"+line+"</p>"
        f5.close() 
 
 
        y5=[]
        for line in x4:
            line=line.replace("題名はここ",title)
            line=line.replace("著者はここ",author)
            line=line.replace("本文はここ",sig)
            ts=t.replace(".txt","")
            line=line.replace("サブタイトルはここ",ts)
            y5.append(line)
 
        n=n+1
        f5x=open("p"+str(n)+".xhtml","w",encoding="UTF-8")
 
        page.append("p"+str(n)+".xhtml")
 
        for line in y5:
            f5x.write(line)
        f5x.close()   
 
 
 
 
def ren():
 
    f1=open("epub/item/xhtml/p-titlepage.xhtml","r",encoding="UTF-8")
    x1=[]
    for line in f1:
        x1.append(line)
    f1.close()    
 
    y1=[]
    for line in x1:
        line=line.replace("題名はここ",title)
        line=line.replace("著者はここ",author)
        y1.append(line)
 
    f1x=open("p-titlepage.xhtml","w",encoding="UTF-8")
 
    for line in y1:
        f1x.write(line)
    f1x.close()   
 
    f2=open("epub/item/xhtml/p-colophon.xhtml","r",encoding="UTF-8")
    x2=[]
    for line in f2:
        x2.append(line)
    f2.close()    
 
    y2=[]
    for line in x2:
        line=line.replace("題名はここ",title)
        line=line.replace("著者はここ",author)
        line=line.replace("出版社はここ",com)
        y2.append(line)
 
    f2x=open("p-colophon.xhtml","w",encoding="UTF-8")
 
    for line in y2:
        f2x.write(line)
    f2x.close()  
 
    f3=open("epub/item/xhtml/p-toc.xhtml","r",encoding="UTF-8")
 
    x3=[]
    for line in f3:
        x3.append(line)
    f3.close()    
 
    y3=[]
    for line in x3:
        line=line.replace("題名はここ",title)
        line=line.replace("著者はここ",author)
        line=line.replace("出版社はここ",com)
        y3.append(line)
 
    f3x=open("p-toc.xhtml","w",encoding="UTF-8")
 
    for line in y3:
        f3x.write(line)
    f3x.close()   
 
    f7=open("epub/item/standard.opf","r",encoding="UTF-8")
 
    x7=[]
    for line in f7:
        x7.append(line)
    f7.close()    
 
 
    pen=""
    for pxs in page:
        xxs=pxs.replace(".xhtml","")
        ppp="<item media-type=\"application/xhtml+xml\" id=\""+xxs+"\" href=\"xhtml/"+pxs+"\"/>"
        pen=pen+ppp
 
    pen2=""
    for pxs in page:
        xxs=pxs.replace(".xhtml","")
        ppp="<itemref linear=\"yes\" idref=\""+xxs+"\" properties=\"page-spread-right\"/>"
        pen2=pen2+ppp
 
    y7=[]
    for line in x7:
        line=line.replace("題名はここ",title)
        line=line.replace("著者はここ",author)
        line=line.replace("出版社はここ",com)
        line=line.replace("ファイルはここ",pen)
        line=line.replace("目次はここ",pen2)
        line=line.replace("コードはここ",codeu)
        y7.append(line)
 
    f7x=open("standard.opf","w",encoding="UTF-8")
 
    for line in y7:
        f7x.write(line)
    f7x.close()   
 
 
 
title="問屋"
author="ちあき"
com="海賊出版"
codeu = str(uuid.uuid1()) 
txt = os.listdir('file')
 
page=[]
 
filex()
 
ren()
 
writez("sig.epub") 
 
最終更新:2018年02月15日 22:13