Commit 863b77a5 authored by Ozzieisaacs's avatar Ozzieisaacs

Fix #711

Fixing for send to kindle after uploading
codecleaning
parent b78130e3
......@@ -114,9 +114,9 @@ def send_registration_mail(e_mail, user_name, default_password, resend=False):
return
def check_send_to_kindle(entry):
'''
"""
returns all available book formats for sending to Kindle
'''
"""
if len(entry.data):
bookformats=list()
if ub.config.config_ebookconverter == 0:
......@@ -156,6 +156,18 @@ def check_send_to_kindle(entry):
return None
# Check if a reader is existing for any of the book formats, if not, return empty list, otherwise return
# list with supported formats
def check_read_formats(entry):
EXTENSIONS_READER = {'TXT', 'PDF', 'EPUB', 'ZIP', 'CBZ', 'TAR', 'CBT', 'RAR', 'CBR'}
bookformats = list()
if len(entry.data):
for ele in iter(entry.data):
if ele.format in EXTENSIONS_READER:
bookformats.append(ele.format.lower())
return bookformats
# Files are processed in the following order/priority:
# 1: If Mobi file is existing, it's directly send to kindle email,
# 2: If Epub file is existing, it's converted and send to kindle email,
......@@ -336,6 +348,7 @@ def delete_book_gdrive(book, book_format):
error =_(u'Book path %(path)s not found on Google Drive', path=book.path) # file not found
return error
def generate_random_password():
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()?"
passlen = 8
......@@ -349,12 +362,14 @@ def update_dir_stucture(book_id, calibrepath):
else:
return update_dir_structure_file(book_id, calibrepath)
def delete_book(book, calibrepath, book_format):
if ub.config.config_use_google_drive:
return delete_book_gdrive(book, book_format)
else:
return delete_book_file(book, calibrepath, book_format)
def get_book_cover(cover_path):
if ub.config.config_use_google_drive:
try:
......@@ -372,6 +387,7 @@ def get_book_cover(cover_path):
else:
return send_from_directory(os.path.join(ub.config.config_calibre_dir, cover_path), "cover.jpg")
# saves book cover to gdrive or locally
def save_cover(url, book_path):
img = requests.get(url)
......@@ -384,7 +400,7 @@ def save_cover(url, book_path):
f = open(os.path.join(tmpDir, "uploaded_cover.jpg"), "wb")
f.write(img.content)
f.close()
uploadFileToEbooksFolder(os.path.join(book_path, 'cover.jpg'), os.path.join(tmpDir, f.name))
gd.uploadFileToEbooksFolder(os.path.join(book_path, 'cover.jpg'), os.path.join(tmpDir, f.name))
web.app.logger.info("Cover is saved on Google Drive")
return True
......@@ -394,6 +410,7 @@ def save_cover(url, book_path):
web.app.logger.info("Cover is saved")
return True
def do_download_file(book, book_format, data, headers):
if ub.config.config_use_google_drive:
startTime = time.time()
......@@ -621,6 +638,7 @@ def get_current_version_info():
return {'hash': content[0], 'datetime': content[1]}
return False
def json_serial(obj):
"""JSON serializer for objects not serializable by default json code"""
......@@ -628,6 +646,7 @@ def json_serial(obj):
return obj.isoformat()
raise TypeError ("Type %s not serializable" % type(obj))
def render_task_status(tasklist):
#helper function to apply localize status information in tasklist entries
renderedtasklist=list()
......
......@@ -57,17 +57,15 @@
</div>
{% endif %}
{% endif %}
{% if entry.data|length %}
{% if reader_list %}
<div class="btn-group" role="group">
<button id="read-in-browser" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-eye-open"></span> {{_('Read in browser')}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="read-in-browser">
{% for format in entry.data %}
{%if format.format|lower == 'epub' or format.format|lower == 'txt' or format.format|lower == 'pdf' or format.format|lower == 'cbr' or format.format|lower == 'cbt' or format.format|lower == 'cbz' %}
<li><a target="_blank" href="{{ url_for('read_book', book_id=entry.id, book_format=format.format|lower) }}">{{format.format}}</a></li>
{% endif %}
{% for format in reader_list %}
<li><a target="_blank" href="{{ url_for('read_book', book_id=entry.id, book_format=format) }}">{{format}}</a></li>
{%endfor%}
</ul>
</div>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment