This repository was archived by the owner on Jun 8, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
convert_ebook_to_kindle_format Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change
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!' )
You can’t perform that action at this time.
0 commit comments