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): ...@@ -114,9 +114,9 @@ def send_registration_mail(e_mail, user_name, default_password, resend=False):
return return
def check_send_to_kindle(entry): def check_send_to_kindle(entry):
''' """
returns all available book formats for sending to Kindle returns all available book formats for sending to Kindle
''' """
if len(entry.data): if len(entry.data):
bookformats=list() bookformats=list()
if ub.config.config_ebookconverter == 0: if ub.config.config_ebookconverter == 0:
...@@ -156,6 +156,18 @@ def check_send_to_kindle(entry): ...@@ -156,6 +156,18 @@ def check_send_to_kindle(entry):
return None 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: # Files are processed in the following order/priority:
# 1: If Mobi file is existing, it's directly send to kindle email, # 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, # 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): ...@@ -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 error =_(u'Book path %(path)s not found on Google Drive', path=book.path) # file not found
return error return error
def generate_random_password(): def generate_random_password():
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()?" s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()?"
passlen = 8 passlen = 8
...@@ -349,12 +362,14 @@ def update_dir_stucture(book_id, calibrepath): ...@@ -349,12 +362,14 @@ def update_dir_stucture(book_id, calibrepath):
else: else:
return update_dir_structure_file(book_id, calibrepath) return update_dir_structure_file(book_id, calibrepath)
def delete_book(book, calibrepath, book_format): def delete_book(book, calibrepath, book_format):
if ub.config.config_use_google_drive: if ub.config.config_use_google_drive:
return delete_book_gdrive(book, book_format) return delete_book_gdrive(book, book_format)
else: else:
return delete_book_file(book, calibrepath, book_format) return delete_book_file(book, calibrepath, book_format)
def get_book_cover(cover_path): def get_book_cover(cover_path):
if ub.config.config_use_google_drive: if ub.config.config_use_google_drive:
try: try:
...@@ -372,6 +387,7 @@ def get_book_cover(cover_path): ...@@ -372,6 +387,7 @@ def get_book_cover(cover_path):
else: else:
return send_from_directory(os.path.join(ub.config.config_calibre_dir, cover_path), "cover.jpg") return send_from_directory(os.path.join(ub.config.config_calibre_dir, cover_path), "cover.jpg")
# saves book cover to gdrive or locally # saves book cover to gdrive or locally
def save_cover(url, book_path): def save_cover(url, book_path):
img = requests.get(url) img = requests.get(url)
...@@ -384,7 +400,7 @@ def save_cover(url, book_path): ...@@ -384,7 +400,7 @@ def save_cover(url, book_path):
f = open(os.path.join(tmpDir, "uploaded_cover.jpg"), "wb") f = open(os.path.join(tmpDir, "uploaded_cover.jpg"), "wb")
f.write(img.content) f.write(img.content)
f.close() 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") web.app.logger.info("Cover is saved on Google Drive")
return True return True
...@@ -394,6 +410,7 @@ def save_cover(url, book_path): ...@@ -394,6 +410,7 @@ def save_cover(url, book_path):
web.app.logger.info("Cover is saved") web.app.logger.info("Cover is saved")
return True return True
def do_download_file(book, book_format, data, headers): def do_download_file(book, book_format, data, headers):
if ub.config.config_use_google_drive: if ub.config.config_use_google_drive:
startTime = time.time() startTime = time.time()
...@@ -621,6 +638,7 @@ def get_current_version_info(): ...@@ -621,6 +638,7 @@ def get_current_version_info():
return {'hash': content[0], 'datetime': content[1]} return {'hash': content[0], 'datetime': content[1]}
return False return False
def json_serial(obj): def json_serial(obj):
"""JSON serializer for objects not serializable by default json code""" """JSON serializer for objects not serializable by default json code"""
...@@ -628,6 +646,7 @@ def json_serial(obj): ...@@ -628,6 +646,7 @@ def json_serial(obj):
return obj.isoformat() return obj.isoformat()
raise TypeError ("Type %s not serializable" % type(obj)) raise TypeError ("Type %s not serializable" % type(obj))
def render_task_status(tasklist): def render_task_status(tasklist):
#helper function to apply localize status information in tasklist entries #helper function to apply localize status information in tasklist entries
renderedtasklist=list() renderedtasklist=list()
......
...@@ -57,17 +57,15 @@ ...@@ -57,17 +57,15 @@
</div> </div>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if entry.data|length %} {% if reader_list %}
<div class="btn-group" role="group"> <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"> <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="glyphicon glyphicon-eye-open"></span> {{_('Read in browser')}}
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" aria-labelledby="read-in-browser"> <ul class="dropdown-menu" aria-labelledby="read-in-browser">
{% for format in entry.data %} {% for format in reader_list %}
{%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}}</a></li>
<li><a target="_blank" href="{{ url_for('read_book', book_id=entry.id, book_format=format.format|lower) }}">{{format.format}}</a></li>
{% endif %}
{%endfor%} {%endfor%}
</ul> </ul>
</div> </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