init
This commit is contained in:
1
python/dn2k/src/.gitignore
vendored
Normal file
1
python/dn2k/src/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.pyc
|
||||
38
python/dn2k/src/ConvertFeed.py
Normal file
38
python/dn2k/src/ConvertFeed.py
Normal file
@@ -0,0 +1,38 @@
|
||||
__author__ = 'dev'
|
||||
import subprocess
|
||||
import os
|
||||
import glob
|
||||
|
||||
EBOOK_CONVERT_CMD = "ebook-convert"
|
||||
OUTPUT_PROFIL_OPTION = "--output-profile"
|
||||
DEFAULT_OUTPUT_PROFIL = "kindle"
|
||||
DEFAULT_FEED_MOBI_FILE_EXTENSION = ".mobi"
|
||||
DEFAULT_FEED_RECIPE_FILE_EXTENSION = ".recipe"
|
||||
|
||||
|
||||
def convert_feed(recipe_path, dst_path, profile=DEFAULT_OUTPUT_PROFIL):
|
||||
recipe_path_abs = os.path.abspath(recipe_path)
|
||||
dst_path_abs = os.path.abspath(dst_path)
|
||||
|
||||
if not os.path.exists(recipe_path_abs):
|
||||
raise os.error.filename
|
||||
|
||||
if os.path.exists(dst_path_abs):
|
||||
os.remove(dst_path_abs)
|
||||
|
||||
subprocess.call([EBOOK_CONVERT_CMD ,recipe_path_abs, dst_path_abs, OUTPUT_PROFIL_OPTION, profile])
|
||||
|
||||
|
||||
def convert_all_feed(recipe_folder, dst_folder, profile=DEFAULT_OUTPUT_PROFIL, recipe_extension=DEFAULT_FEED_RECIPE_FILE_EXTENSION, mobi_extension=DEFAULT_FEED_MOBI_FILE_EXTENSION):
|
||||
recipe_folder_path_abs = os.path.abspath(recipe_folder)
|
||||
dst_folder_path_abs = os.path.abspath(dst_folder)
|
||||
|
||||
if not os.path.exists(recipe_folder_path_abs) or not os.path.exists(dst_folder_path_abs):
|
||||
raise os.error.filename
|
||||
|
||||
for file in glob.glob(os.path.join(recipe_folder_path_abs, "*" + recipe_extension)):
|
||||
file_base_name = os.path.splitext(os.path.basename(file))[0]
|
||||
dst_path_abs = os.path.join(dst_folder_path_abs, file_base_name + mobi_extension)
|
||||
if os.path.exists(dst_path_abs):
|
||||
os.remove(dst_path_abs)
|
||||
convert_feed(file, dst_path_abs, profile)
|
||||
15
python/dn2k/src/SendFeed.py
Normal file
15
python/dn2k/src/SendFeed.py
Normal file
@@ -0,0 +1,15 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
EBOOK_SEND_CMD = "calibre-smtp"
|
||||
|
||||
|
||||
def send_feed(mobi_path, feed_name, sender_mail_address, dst_mail_address):
|
||||
subprocess.call([EBOOK_SEND_CMD, "-a", mobi_path, "-s", feed_name, sender_mail_address, dst_mail_address, feed_name])
|
||||
|
||||
|
||||
def send_feeds(feedDict, sender_mail_address, dst_mail_address):
|
||||
for feed_name, mobi_path in feedDict.items():
|
||||
send_feed(mobi_path, feed_name, sender_mail_address, dst_mail_address)
|
||||
Reference in New Issue
Block a user