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
791f4a80
Commit
791f4a80
authored
Aug 12, 2018
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #455
parent
7be328c5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
88 deletions
+87
-88
web.py
cps/web.py
+87
-88
No files found.
cps/web.py
View file @
791f4a80
...
@@ -555,10 +555,41 @@ def modify_database_object(input_elements, db_book_object, db_object, db_session
...
@@ -555,10 +555,41 @@ def modify_database_object(input_elements, db_book_object, db_object, db_session
else
:
# db_type should be tag, or languages
else
:
# db_type should be tag, or languages
new_element
=
db_object
(
add_element
)
new_element
=
db_object
(
add_element
)
db_session
.
add
(
new_element
)
db_session
.
add
(
new_element
)
new_element
=
db
.
session
.
query
(
db_object
)
.
filter
(
db_filter
==
add_element
)
.
first
()
# add element to book
# add element to book
db_book_object
.
append
(
new_element
)
db_book_object
.
append
(
new_element
)
# read search results from calibre-database and return it
def
get_search_results
(
term
):
q
=
list
()
authorterms
=
re
.
split
(
"[, ]+"
,
term
)
for
authorterm
in
authorterms
:
q
.
append
(
db
.
Books
.
authors
.
any
(
db
.
Authors
.
name
.
ilike
(
"
%
"
+
authorterm
+
"
%
"
)))
db
.
session
.
connection
()
.
connection
.
connection
.
create_function
(
"lower"
,
1
,
db
.
lcase
)
db
.
Books
.
authors
.
any
(
db
.
Authors
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
))
return
db
.
session
.
query
(
db
.
Books
)
.
filter
(
common_filters
())
.
filter
(
db
.
or_
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
series
.
any
(
db
.
Series
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
authors
.
any
(
and_
(
*
q
)),
db
.
Books
.
publishers
.
any
(
db
.
Publishers
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
title
.
ilike
(
"
%
"
+
term
+
"
%
"
)))
.
all
()
def
feed_search
(
term
):
if
term
:
term
=
term
.
strip
()
.
lower
()
entries
=
get_search_results
(
term
)
entriescount
=
len
(
entries
)
if
len
(
entries
)
>
0
else
1
pagination
=
Pagination
(
1
,
entriescount
,
entriescount
)
xml
=
render_title_template
(
'feed.xml'
,
searchterm
=
term
,
entries
=
entries
,
pagination
=
pagination
)
else
:
xml
=
render_title_template
(
'feed.xml'
,
searchterm
=
""
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/atom+xml; charset=utf-8"
return
response
def
render_title_template
(
*
args
,
**
kwargs
):
def
render_title_template
(
*
args
,
**
kwargs
):
return
render_template
(
instance
=
config
.
config_calibre_web_title
,
*
args
,
**
kwargs
)
return
render_template
(
instance
=
config
.
config_calibre_web_title
,
*
args
,
**
kwargs
)
...
@@ -607,26 +638,6 @@ def feed_normal_search():
...
@@ -607,26 +638,6 @@ def feed_normal_search():
return
feed_search
(
request
.
args
.
get
(
"query"
)
.
strip
())
return
feed_search
(
request
.
args
.
get
(
"query"
)
.
strip
())
def
feed_search
(
term
):
if
term
:
term
=
term
.
strip
()
.
lower
()
db
.
session
.
connection
()
.
connection
.
connection
.
create_function
(
"lower"
,
1
,
db
.
lcase
)
entries
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
common_filters
())
.
filter
(
db
.
or_
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
series
.
any
(
db
.
Series
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
authors
.
any
(
db
.
Authors
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
publishers
.
any
(
db
.
Publishers
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
title
.
ilike
(
"
%
"
+
term
+
"
%
"
)))
.
all
()
entriescount
=
len
(
entries
)
if
len
(
entries
)
>
0
else
1
pagination
=
Pagination
(
1
,
entriescount
,
entriescount
)
xml
=
render_title_template
(
'feed.xml'
,
searchterm
=
term
,
entries
=
entries
,
pagination
=
pagination
)
else
:
xml
=
render_title_template
(
'feed.xml'
,
searchterm
=
""
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/atom+xml; charset=utf-8"
return
response
@
app
.
route
(
"/opds/new"
)
@
app
.
route
(
"/opds/new"
)
@
requires_basic_auth_if_no_ano
@
requires_basic_auth_if_no_ano
def
feed_new
():
def
feed_new
():
...
@@ -941,7 +952,7 @@ def get_authors_json():
...
@@ -941,7 +952,7 @@ def get_authors_json():
if
request
.
method
==
"GET"
:
if
request
.
method
==
"GET"
:
query
=
request
.
args
.
get
(
'q'
)
query
=
request
.
args
.
get
(
'q'
)
entries
=
db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
.
ilike
(
"
%
"
+
query
+
"
%
"
))
.
all
()
entries
=
db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
.
ilike
(
"
%
"
+
query
+
"
%
"
))
.
all
()
json_dumps
=
json
.
dumps
([
dict
(
name
=
r
.
name
)
for
r
in
entries
])
json_dumps
=
json
.
dumps
([
dict
(
name
=
r
.
name
.
replace
(
'|'
,
','
)
)
for
r
in
entries
])
return
json_dumps
return
json_dumps
...
@@ -955,57 +966,6 @@ def get_tags_json():
...
@@ -955,57 +966,6 @@ def get_tags_json():
return
json_dumps
return
json_dumps
@
app
.
route
(
"/get_update_status"
,
methods
=
[
'GET'
])
@
login_required_if_no_ano
def
get_update_status
():
status
=
{}
if
request
.
method
==
"GET"
:
# should be automatically replaced by git with current commit hash
commit_id
=
'$Format:
%
H$'
# ToDo: Handle server not reachable -> ValueError:
commit
=
requests
.
get
(
'https://api.github.com/repos/janeczku/calibre-web/git/refs/heads/master'
)
.
json
()
if
"object"
in
commit
and
commit
[
'object'
][
'sha'
]
!=
commit_id
:
status
[
'status'
]
=
True
commitdate
=
requests
.
get
(
'https://api.github.com/repos/janeczku/calibre-web/git/commits/'
+
commit
[
'object'
][
'sha'
])
.
json
()
if
"committer"
in
commitdate
:
form_date
=
datetime
.
datetime
.
strptime
(
commitdate
[
'committer'
][
'date'
],
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ"
)
status
[
'commit'
]
=
format_datetime
(
form_date
,
format
=
'short'
,
locale
=
get_locale
())
else
:
status
[
'commit'
]
=
u'Unknown'
else
:
status
[
'status'
]
=
False
return
json
.
dumps
(
status
)
@
app
.
route
(
"/get_updater_status"
,
methods
=
[
'GET'
,
'POST'
])
@
login_required
@
admin_required
def
get_updater_status
():
status
=
{}
if
request
.
method
==
"POST"
:
commit
=
request
.
form
.
to_dict
()
if
"start"
in
commit
and
commit
[
'start'
]
==
'True'
:
text
=
{
"1"
:
_
(
u'Requesting update package'
),
"2"
:
_
(
u'Downloading update package'
),
"3"
:
_
(
u'Unzipping update package'
),
"4"
:
_
(
u'Files are replaced'
),
"5"
:
_
(
u'Database connections are closed'
),
"6"
:
_
(
u'Server is stopped'
),
"7"
:
_
(
u'Update finished, please press okay and reload page'
)
}
status
[
'text'
]
=
text
helper
.
updater_thread
=
helper
.
Updater
()
helper
.
updater_thread
.
start
()
status
[
'status'
]
=
helper
.
updater_thread
.
get_update_status
()
elif
request
.
method
==
"GET"
:
try
:
status
[
'status'
]
=
helper
.
updater_thread
.
get_update_status
()
except
Exception
:
status
[
'status'
]
=
7
return
json
.
dumps
(
status
)
@
app
.
route
(
"/get_languages_json"
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
"/get_languages_json"
,
methods
=
[
'GET'
,
'POST'
])
@
login_required_if_no_ano
@
login_required_if_no_ano
def
get_languages_json
():
def
get_languages_json
():
...
@@ -1060,6 +1020,57 @@ def get_matching_tags():
...
@@ -1060,6 +1020,57 @@ def get_matching_tags():
return
json_dumps
return
json_dumps
@
app
.
route
(
"/get_update_status"
,
methods
=
[
'GET'
])
@
login_required_if_no_ano
def
get_update_status
():
status
=
{}
if
request
.
method
==
"GET"
:
# should be automatically replaced by git with current commit hash
commit_id
=
'$Format:
%
H$'
# ToDo: Handle server not reachable -> ValueError:
commit
=
requests
.
get
(
'https://api.github.com/repos/janeczku/calibre-web/git/refs/heads/master'
)
.
json
()
if
"object"
in
commit
and
commit
[
'object'
][
'sha'
]
!=
commit_id
:
status
[
'status'
]
=
True
commitdate
=
requests
.
get
(
'https://api.github.com/repos/janeczku/calibre-web/git/commits/'
+
commit
[
'object'
][
'sha'
])
.
json
()
if
"committer"
in
commitdate
:
form_date
=
datetime
.
datetime
.
strptime
(
commitdate
[
'committer'
][
'date'
],
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ"
)
status
[
'commit'
]
=
format_datetime
(
form_date
,
format
=
'short'
,
locale
=
get_locale
())
else
:
status
[
'commit'
]
=
u'Unknown'
else
:
status
[
'status'
]
=
False
return
json
.
dumps
(
status
)
@
app
.
route
(
"/get_updater_status"
,
methods
=
[
'GET'
,
'POST'
])
@
login_required
@
admin_required
def
get_updater_status
():
status
=
{}
if
request
.
method
==
"POST"
:
commit
=
request
.
form
.
to_dict
()
if
"start"
in
commit
and
commit
[
'start'
]
==
'True'
:
text
=
{
"1"
:
_
(
u'Requesting update package'
),
"2"
:
_
(
u'Downloading update package'
),
"3"
:
_
(
u'Unzipping update package'
),
"4"
:
_
(
u'Files are replaced'
),
"5"
:
_
(
u'Database connections are closed'
),
"6"
:
_
(
u'Server is stopped'
),
"7"
:
_
(
u'Update finished, please press okay and reload page'
)
}
status
[
'text'
]
=
text
helper
.
updater_thread
=
helper
.
Updater
()
helper
.
updater_thread
.
start
()
status
[
'status'
]
=
helper
.
updater_thread
.
get_update_status
()
elif
request
.
method
==
"GET"
:
try
:
status
[
'status'
]
=
helper
.
updater_thread
.
get_update_status
()
except
Exception
:
status
[
'status'
]
=
7
return
json
.
dumps
(
status
)
@
app
.
route
(
"/"
,
defaults
=
{
'page'
:
1
})
@
app
.
route
(
"/"
,
defaults
=
{
'page'
:
1
})
@
app
.
route
(
'/page/<int:page>'
)
@
app
.
route
(
'/page/<int:page>'
)
@
login_required_if_no_ano
@
login_required_if_no_ano
...
@@ -1704,20 +1715,8 @@ def update():
...
@@ -1704,20 +1715,8 @@ def update():
@
login_required_if_no_ano
@
login_required_if_no_ano
def
search
():
def
search
():
term
=
request
.
args
.
get
(
"query"
)
.
strip
()
.
lower
()
term
=
request
.
args
.
get
(
"query"
)
.
strip
()
.
lower
()
if
term
:
if
term
:
db
.
session
.
connection
()
.
connection
.
connection
.
create_function
(
"lower"
,
1
,
db
.
lcase
)
entries
=
get_search_results
(
term
)
entries
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
common_filters
())
.
filter
(
db
.
or_
(
db
.
Books
.
tags
.
any
(
db
.
Tags
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
series
.
any
(
db
.
Series
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
authors
.
any
(
db
.
Authors
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
publishers
.
any
(
db
.
Publishers
.
name
.
ilike
(
"
%
"
+
term
+
"
%
"
)),
db
.
Books
.
title
.
ilike
(
"
%
"
+
term
+
"
%
"
)))
.
all
()
# entries = db.session.query(db.Books).with_entities(db.Books.title).filter(db.Books.title.ilike("%" + term + "%")).all()
# result = db.session.execute("select name from authors where lower(name) like '%" + term.lower() + "%'")
# entries = result.fetchall()
# result.close()
return
render_title_template
(
'search.html'
,
searchterm
=
term
,
entries
=
entries
,
page
=
"search"
)
return
render_title_template
(
'search.html'
,
searchterm
=
term
,
entries
=
entries
,
page
=
"search"
)
else
:
else
:
return
render_title_template
(
'search.html'
,
searchterm
=
""
,
page
=
"search"
)
return
render_title_template
(
'search.html'
,
searchterm
=
""
,
page
=
"search"
)
...
@@ -1741,14 +1740,14 @@ def advanced_search():
...
@@ -1741,14 +1740,14 @@ def advanced_search():
publisher
=
request
.
args
.
get
(
"publisher"
)
publisher
=
request
.
args
.
get
(
"publisher"
)
pub_start
=
request
.
args
.
get
(
"Publishstart"
)
pub_start
=
request
.
args
.
get
(
"Publishstart"
)
pub_end
=
request
.
args
.
get
(
"Publishend"
)
pub_end
=
request
.
args
.
get
(
"Publishend"
)
if
author_name
:
author_name
=
author_name
.
strip
()
.
lower
()
if
author_name
:
author_name
=
author_name
.
strip
()
.
lower
()
.
replace
(
','
,
'|'
)
if
book_title
:
book_title
=
book_title
.
strip
()
.
lower
()
if
book_title
:
book_title
=
book_title
.
strip
()
.
lower
()
if
publisher
:
publisher
=
publisher
.
strip
()
.
lower
()
if
publisher
:
publisher
=
publisher
.
strip
()
.
lower
()
if
include_tag_inputs
or
exclude_tag_inputs
or
include_series_inputs
or
exclude_series_inputs
or
\
if
include_tag_inputs
or
exclude_tag_inputs
or
include_series_inputs
or
exclude_series_inputs
or
\
include_languages_inputs
or
exclude_languages_inputs
or
author_name
or
book_title
or
\
include_languages_inputs
or
exclude_languages_inputs
or
author_name
or
book_title
or
\
publisher
or
pub_start
or
pub_end
:
publisher
or
pub_start
or
pub_end
:
searchterm
=
[]
searchterm
=
[]
searchterm
.
extend
((
author_name
,
book_title
,
publisher
))
searchterm
.
extend
((
author_name
.
replace
(
'|'
,
','
)
,
book_title
,
publisher
))
if
pub_start
:
if
pub_start
:
try
:
try
:
searchterm
.
extend
([
_
(
u"Published after
%
s"
%
searchterm
.
extend
([
_
(
u"Published after
%
s"
%
...
...
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