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
da8d0c2a
Commit
da8d0c2a
authored
Mar 05, 2017
by
林檎
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix/syntax-python3-20170305' into travis
parents
f315d54c
c3fd205b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
23 deletions
+42
-23
cps.py
cps.py
+3
-1
book_formats.py
cps/book_formats.py
+5
-5
db.py
cps/db.py
+2
-1
fb2.py
cps/fb2.py
+3
-3
helper.py
cps/helper.py
+12
-6
ub.py
cps/ub.py
+2
-1
web.py
cps/web.py
+13
-6
requirements.txt
requirements.txt
+2
-0
No files found.
cps.py
View file @
da8d0c2a
...
...
@@ -6,7 +6,9 @@ import sys
base_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
# Insert local directories into path
sys
.
path
.
insert
(
0
,
os
.
path
.
join
(
base_path
,
'vendor'
))
sys
.
path
.
append
(
base_path
)
sys
.
path
.
append
(
os
.
path
.
join
(
base_path
,
'cps'
))
sys
.
path
.
append
(
os
.
path
.
join
(
base_path
,
'vendor'
))
from
cps
import
web
from
tornado.wsgi
import
WSGIContainer
...
...
cps/book_formats.py
View file @
da8d0c2a
...
...
@@ -14,28 +14,28 @@ try:
from
wand.image
import
Image
from
wand
import
version
as
ImageVersion
use_generic_pdf_cover
=
False
except
ImportError
,
e
:
except
ImportError
as
e
:
logger
.
warning
(
'cannot import Image, generating pdf covers for pdf uploads will not work:
%
s'
,
e
)
use_generic_pdf_cover
=
True
try
:
from
PyPDF2
import
PdfFileReader
from
PyPDF2
import
__version__
as
PyPdfVersion
use_pdf_meta
=
True
except
ImportError
,
e
:
except
ImportError
as
e
:
logger
.
warning
(
'cannot import PyPDF2, extracting pdf metadata will not work:
%
s'
,
e
)
use_pdf_meta
=
False
try
:
import
epub
use_epub_meta
=
True
except
ImportError
,
e
:
except
ImportError
as
e
:
logger
.
warning
(
'cannot import epub, extracting epub metadata will not work:
%
s'
,
e
)
use_epub_meta
=
False
try
:
import
fb2
use_fb2_meta
=
True
except
ImportError
,
e
:
except
ImportError
as
e
:
logger
.
warning
(
'cannot import fb2, extracting fb2 metadata will not work:
%
s'
,
e
)
use_fb2_meta
=
False
...
...
@@ -48,7 +48,7 @@ def process(tmp_file_path, original_file_name, original_file_extension):
return
epub
.
get_epub_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
)
if
".FB2"
==
original_file_extension
.
upper
()
and
use_fb2_meta
is
True
:
return
fb2
.
get_fb2_info
(
tmp_file_path
,
original_file_extension
)
except
Exception
,
e
:
except
Exception
as
e
:
logger
.
warning
(
'cannot parse metadata, using default:
%
s'
,
e
)
return
default_meta
(
tmp_file_path
,
original_file_name
,
original_file_extension
)
...
...
cps/db.py
View file @
da8d0c2a
...
...
@@ -294,7 +294,8 @@ def setup_db():
return
False
dbpath
=
os
.
path
.
join
(
config
.
config_calibre_dir
,
"metadata.db"
)
engine
=
create_engine
(
'sqlite:///{0}'
.
format
(
dbpath
.
encode
(
'utf-8'
)),
echo
=
False
,
isolation_level
=
"SERIALIZABLE"
)
#engine = create_engine('sqlite:///{0}'.format(dbpath.encode('utf-8')), echo=False, isolation_level="SERIALIZABLE")
engine
=
create_engine
(
'sqlite:///'
+
dbpath
,
echo
=
False
,
isolation_level
=
"SERIALIZABLE"
)
try
:
conn
=
engine
.
connect
()
...
...
cps/fb2.py
View file @
da8d0c2a
...
...
@@ -37,16 +37,16 @@ def get_fb2_info(tmp_file_path, original_file_extension):
first_name
=
u''
return
first_name
+
' '
+
middle_name
+
' '
+
last_name
author
=
unicode
(
", "
.
join
(
map
(
get_author
,
authors
)))
author
=
str
(
", "
.
join
(
map
(
get_author
,
authors
)))
title
=
tree
.
xpath
(
'/fb:FictionBook/fb:description/fb:title-info/fb:book-title/text()'
,
namespaces
=
ns
)
if
len
(
title
):
title
=
unicode
(
title
[
0
])
title
=
str
(
title
[
0
])
else
:
title
=
u''
description
=
tree
.
xpath
(
'/fb:FictionBook/fb:description/fb:publish-info/fb:book-name/text()'
,
namespaces
=
ns
)
if
len
(
description
):
description
=
unicode
(
description
[
0
])
description
=
str
(
description
[
0
])
else
:
description
=
u''
...
...
cps/helper.py
View file @
da8d0c2a
...
...
@@ -13,11 +13,17 @@ import os
import
traceback
import
re
import
unicodedata
from
StringIO
import
StringIO
try
:
from
StringIO
import
StringIO
from
email.MIMEBase
import
MIMEBase
from
email.MIMEMultipart
import
MIMEMultipart
from
email.MIMEText
import
MIMEText
except
ImportError
:
from
io
import
StringIO
from
email.mime.base
import
MIMEBase
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
from
email
import
encoders
from
email.MIMEBase
import
MIMEBase
from
email.MIMEMultipart
import
MIMEMultipart
from
email.MIMEText
import
MIMEText
from
email.generator
import
Generator
from
email.utils
import
formatdate
from
email.utils
import
make_msgid
...
...
@@ -147,7 +153,7 @@ def send_raw_email(kindle_mail, msg):
smtplib
.
stderr
=
org_stderr
except
(
socket
.
error
,
smtplib
.
SMTPRecipientsRefused
,
smtplib
.
SMTPException
)
,
e
:
except
(
socket
.
error
,
smtplib
.
SMTPRecipientsRefused
,
smtplib
.
SMTPException
)
as
e
:
app
.
logger
.
error
(
traceback
.
print_exc
())
return
_
(
"Failed to send mail:
%
s"
%
str
(
e
))
...
...
@@ -239,7 +245,7 @@ def get_valid_filename(value, replace_whitespace=True):
value
=
value
.
replace
(
u'ß'
,
u'ss'
)
value
=
unicodedata
.
normalize
(
'NFKD'
,
value
)
re_slugify
=
re
.
compile
(
'[
\
W
\
s-]'
,
re
.
UNICODE
)
value
=
unicode
(
re_slugify
.
sub
(
''
,
value
)
.
strip
())
value
=
str
(
re_slugify
.
sub
(
''
,
value
)
.
strip
())
if
replace_whitespace
:
#*+:\"/<>? werden durch _ ersetzt
value
=
re
.
sub
(
'[
\
*
\
+:
\\\"
/<>
\
?]+'
,
u'_'
,
value
,
flags
=
re
.
U
)
...
...
cps/ub.py
View file @
da8d0c2a
...
...
@@ -10,6 +10,7 @@ import os
import
logging
from
werkzeug.security
import
generate_password_hash
from
flask_babel
import
gettext
as
_
from
builtins
import
str
dbpath
=
os
.
path
.
join
(
os
.
path
.
normpath
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
os
.
sep
+
".."
+
os
.
sep
),
"app.db"
)
engine
=
create_engine
(
'sqlite:///{0}'
.
format
(
dbpath
),
echo
=
False
)
...
...
@@ -90,7 +91,7 @@ class UserBase:
return
False
def
get_id
(
self
):
return
unicode
(
self
.
id
)
return
str
(
self
.
id
)
def
filter_language
(
self
):
return
self
.
default_language
...
...
cps/web.py
View file @
da8d0c2a
...
...
@@ -47,12 +47,19 @@ import db
from
shutil
import
move
,
copyfile
from
tornado.ioloop
import
IOLoop
from
tornado
import
version
as
tornadoVersion
from
builtins
import
str
try
:
from
imp
import
reload
from
past.builtins
import
xrange
except
:
pass
try
:
from
wand.image
import
Image
use_generic_pdf_cover
=
False
except
ImportError
,
e
:
except
ImportError
as
e
:
use_generic_pdf_cover
=
True
from
cgi
import
escape
...
...
@@ -1044,8 +1051,8 @@ def stats():
stdin
=
subprocess
.
PIPE
)
p
.
wait
()
for
lines
in
p
.
stdout
.
readlines
():
if
re
.
search
(
'Amazon kindlegen
\
('
,
lines
):
versions
[
'KindlegenVersion'
]
=
lines
if
re
.
search
(
'Amazon kindlegen
\
('
,
str
(
lines
)
):
versions
[
'KindlegenVersion'
]
=
str
(
lines
)
versions
[
'PythonVersion'
]
=
sys
.
version
versions
[
'babel'
]
=
babelVersion
versions
[
'sqlalchemy'
]
=
sqlalchemyVersion
...
...
@@ -2186,12 +2193,12 @@ def upload():
return
redirect
(
url_for
(
'index'
))
try
:
copyfile
(
meta
.
file_path
,
saved_filename
)
except
OSError
,
e
:
except
OSError
as
e
:
flash
(
_
(
u"Failed to store file
%
s (Permission denied)."
%
saved_filename
),
category
=
"error"
)
return
redirect
(
url_for
(
'index'
))
try
:
os
.
unlink
(
meta
.
file_path
)
except
OSError
,
e
:
except
OSError
as
e
:
flash
(
_
(
u"Failed to delete file
%
s (Permission denied)."
%
meta
.
file_path
),
category
=
"warning"
)
file_size
=
os
.
path
.
getsize
(
saved_filename
)
...
...
@@ -2223,7 +2230,7 @@ def upload():
db
.
session
.
add
(
db_language
)
# combine path and normalize path from windows systems
path
=
os
.
path
.
join
(
author_dir
,
title_dir
)
.
replace
(
'
\\
'
,
'/'
)
db_book
=
db
.
Books
(
title
,
""
,
db_author
.
sort
,
datetime
.
datetime
.
now
(),
datetime
.
datetime
(
101
,
01
,
0
1
),
1
,
db_book
=
db
.
Books
(
title
,
""
,
db_author
.
sort
,
datetime
.
datetime
.
now
(),
datetime
.
datetime
(
101
,
1
,
1
),
1
,
datetime
.
datetime
.
now
(),
path
,
has_cover
,
db_author
,
[],
db_language
)
db_book
.
authors
.
append
(
db_author
)
if
db_language
is
not
None
:
...
...
requirements.txt
0 → 100644
View file @
da8d0c2a
future
sqlalchemy
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