Skip to content

Instantly share code, notes, and snippets.

@3ki5tj
Created April 7, 2018 05:17
Show Gist options
  • Save 3ki5tj/58b0026b5afd8b04f4b009fc84e8b794 to your computer and use it in GitHub Desktop.
Save 3ki5tj/58b0026b5afd8b04f4b009fc84e8b794 to your computer and use it in GitHub Desktop.
#!/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