-
-
Save rohshall/8980b8f73374c767dbe0a82bcf8ae86c to your computer and use it in GitHub Desktop.
A script to process azw3, epub, and mobi into text files using calibre ebook-convert
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
import os | |
import shlex | |
import subprocess | |
sink = open('/dev/null', 'w') | |
def convert_book(input, output): | |
subprocess.call("ebook-convert" + " " + input + " " + output, shell=True, stdout=sink, stderr=sink) | |
files_to_convert = [file for file in os.listdir("/home/salil/Documents/Books/mobis")] | |
for file in files_to_convert: | |
# Remove extension for conversion to TXT | |
base = file.split("." + file)[0] | |
output = base + ".epub" | |
full_input = shlex.quote(os.path.join("/home/salil/Documents/Books/mobis", file)) | |
full_output = shlex.quote(os.path.join("/home/salil/Documents/Books/mobis", output)) | |
print("Creating {}".format(output)) | |
convert_book(full_input, full_output) | |
sink.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment