Skip to content

Instantly share code, notes, and snippets.

@rohshall
Forked from EsotericAlgorithm/convert.py
Last active February 28, 2024 15:25
Show Gist options
  • Save rohshall/8980b8f73374c767dbe0a82bcf8ae86c to your computer and use it in GitHub Desktop.
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
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