Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.

Commit 930a916

Browse files
Merge pull request #48 from roopeshvs/master
Added Script To Convert Ebook to Kindle
2 parents 5665858 + 4ff22dc commit 930a916

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Convert Ebook To Kindle Format
2+
3+
Converts .epub to .azw3 format
4+
5+
## Pre-Requisites
6+
7+
- Install [Calibre](https://calibre-ebook.com/download)
8+
9+
## Instructions
10+
11+
- Run the program with command-line arguments
12+
13+
`python convert.py {ebook_file_path}` or `python convert {ebook_file_path}`
14+
15+
depending on your system to convert the ebook to kindle format.
16+
17+
- The Output Location is same as the source.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
import os
3+
import subprocess
4+
5+
6+
def epub_to_awz3(file_path):
7+
"""
8+
Convert An Ebook To Kindle Format.
9+
"""
10+
if file_path.split('.')[-1] == "epub":
11+
if os.path.isfile(file_path):
12+
output_path = get_output_path(file_path)
13+
try:
14+
subprocess.call(["ebook-convert", file_path, output_path])
15+
except Exception as e:
16+
print(e)
17+
else:
18+
print("Bad File Path!")
19+
else:
20+
print("Bad File Extension!")
21+
22+
def get_output_path(file_path):
23+
"""
24+
Helper Function That Returns Output Filepath At
25+
The Same Location Of Source With Changed Extension
26+
"""
27+
output_path = file_path.split('.')
28+
output_path[-1] = ".azw3"
29+
return "".join(output_path)
30+
31+
if __name__ == "__main__":
32+
try:
33+
file_path = sys.argv[1]
34+
except Exception as e:
35+
print(e)
36+
print('Please Enter The Ebook File Path as a Command-Line Argument!')
37+
exit(0)
38+
epub_to_awz3(file_path)
39+
print('Succesfully Converted!')

0 commit comments

Comments
 (0)