Created
April 7, 2018 05:17
-
-
Save 3ki5tj/58b0026b5afd8b04f4b009fc84e8b794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' create an .epub file from a given directory ''' | |
import os, sys, zipfile | |
import Tkinter, tkFileDialog | |
def zipdir(zipf, path): | |
''' add everything under path under zipf ''' | |
for root, dirs, files in os.walk(path): | |
for file in files: | |
zipf.write(os.path.join(root, file)) | |
def zipepub(fn, dir): | |
''' create an .epub file from current directory ''' | |
if dir: os.chdir(dir) | |
zipf = zipfile.ZipFile(fn, 'w', zipfile.ZIP_DEFLATED) | |
zipf.write("mimetype") | |
zipdir(zipf, 'OEBPS') | |
zipdir(zipf, 'META-INF') | |
zipf.close() | |
if __name__ == '__main__': | |
root = Tkinter.Tk() | |
root.withdraw() | |
#file_path = tkFileDialog.askopenfilename() | |
dir = tkFileDialog.askdirectory(title="Select directory of your ebook") | |
fnout = tkFileDialog.asksaveasfilename(initialdir=dir, title="Save the output file name", filetypes = (("ePUB files","*.epub"),("all files","*.*"))) | |
zipepub(fnout, dir) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment