Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
863b77a5
Commit
863b77a5
authored
Nov 25, 2018
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #711
Fixing for send to kindle after uploading codecleaning
parent
b78130e3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
64 deletions
+73
-64
helper.py
cps/helper.py
+22
-3
detail.html
cps/templates/detail.html
+3
-5
web.py
cps/web.py
+48
-56
No files found.
cps/helper.py
View file @
863b77a5
...
...
@@ -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
()
...
...
cps/templates/detail.html
View file @
863b77a5
...
...
@@ -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>
...
...
cps/web.py
View file @
863b77a5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment