File size: 796 Bytes
a37b18d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import os
import subprocess
def convert_epubs_to_txt(epubs_dir, txt_dir):
if not os.path.exists(txt_dir):
os.makedirs(txt_dir)
for root, dirs, files in os.walk(epubs_dir):
for file in files:
if file.endswith('.epub'):
epub_path = os.path.join(root, file)
txt_filename = os.path.splitext(file)[0] + '.txt'
txt_path = os.path.join(txt_dir, txt_filename)
# Run the epub2txt-all.py script
subprocess.run(['python', 'epub2txt-all.py', epub_path, txt_path, "-q"])
if __name__ == "__main__":
epubs_directory = './epubs' # Change this to the directory containing your EPUB files
txt_directory = './txt'
convert_epubs_to_txt(epubs_directory, txt_directory) |