mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-19 14:40:30 +00:00
Bugfixes from Testrun
Update teststatus
This commit is contained in:
parent
d75d95f401
commit
a8680a45ca
@ -914,7 +914,8 @@ class CalibreDB:
|
|||||||
.filter(Languages.lang_code == None)
|
.filter(Languages.lang_code == None)
|
||||||
.filter(self.common_filters())
|
.filter(self.common_filters())
|
||||||
.count())
|
.count())
|
||||||
tags.append([Category(_("None"), "none"), no_lang_count])
|
if no_lang_count:
|
||||||
|
tags.append([Category(_("None"), "none"), no_lang_count])
|
||||||
return sorted(tags, key=lambda x: x[0].name, reverse=reverse_order)
|
return sorted(tags, key=lambda x: x[0].name, reverse=reverse_order)
|
||||||
else:
|
else:
|
||||||
if not languages:
|
if not languages:
|
||||||
@ -993,10 +994,12 @@ class Category:
|
|||||||
name = None
|
name = None
|
||||||
id = None
|
id = None
|
||||||
count = None
|
count = None
|
||||||
|
rating = None
|
||||||
|
|
||||||
def __init__(self, name, cat_id):
|
def __init__(self, name, cat_id, rating=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.id = cat_id
|
self.id = cat_id
|
||||||
|
self.rating = rating
|
||||||
self.count = 1
|
self.count = 1
|
||||||
|
|
||||||
'''class Count:
|
'''class Count:
|
||||||
|
@ -56,13 +56,13 @@ class Amazon(Metadata):
|
|||||||
self, query: str, generic_cover: str = "", locale: str = "en"
|
self, query: str, generic_cover: str = "", locale: str = "en"
|
||||||
) -> Optional[List[MetaRecord]]:
|
) -> Optional[List[MetaRecord]]:
|
||||||
#timer=time()
|
#timer=time()
|
||||||
def inner(link,index) -> tuple[dict,int]:
|
def inner(link, index) -> [dict, int]:
|
||||||
with self.session as session:
|
with self.session as session:
|
||||||
try:
|
try:
|
||||||
r = session.get(f"https://www.amazon.com/{link}")
|
r = session.get(f"https://www.amazon.com/{link}")
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except Exception as e:
|
except Exception as ex:
|
||||||
log.warning(e)
|
log.warning(ex)
|
||||||
return
|
return
|
||||||
long_soup = BS(r.text, "lxml") #~4sec :/
|
long_soup = BS(r.text, "lxml") #~4sec :/
|
||||||
soup2 = long_soup.find("div", attrs={"cel_widget_id": "dpx-books-ppd_csm_instrumentation_wrapper"})
|
soup2 = long_soup.find("div", attrs={"cel_widget_id": "dpx-books-ppd_csm_instrumentation_wrapper"})
|
||||||
@ -126,16 +126,16 @@ class Amazon(Metadata):
|
|||||||
headers=self.headers)
|
headers=self.headers)
|
||||||
results.raise_for_status()
|
results.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as e:
|
except requests.exceptions.HTTPError as e:
|
||||||
log.error_or_exception(e)
|
log.error_or_exception(e)
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning(e)
|
log.warning(e)
|
||||||
return None
|
return None
|
||||||
soup = BS(results.text, 'html.parser')
|
soup = BS(results.text, 'html.parser')
|
||||||
links_list = [next(filter(lambda i: "digital-text" in i["href"], x.findAll("a")))["href"] for x in
|
links_list = [next(filter(lambda i: "digital-text" in i["href"], x.findAll("a")))["href"] for x in
|
||||||
soup.findAll("div", attrs={"data-component-type": "s-search-result"})]
|
soup.findAll("div", attrs={"data-component-type": "s-search-result"})]
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
|
||||||
fut = {executor.submit(inner, link, index) for index, link in enumerate(links_list[:5])}
|
fut = {executor.submit(inner, link, index) for index, link in enumerate(links_list[:5])}
|
||||||
val=list(map(lambda x : x.result() ,concurrent.futures.as_completed(fut)))
|
val = list(map(lambda x : x.result() ,concurrent.futures.as_completed(fut)))
|
||||||
result=list(filter(lambda x: x, val))
|
result = list(filter(lambda x: x, val))
|
||||||
return [x[0] for x in sorted(result, key=itemgetter(1))] #sort by amazons listing order for best relevance
|
return [x[0] for x in sorted(result, key=itemgetter(1))] #sort by amazons listing order for best relevance
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="second" class="col-xs-12 col-sm-6">
|
<div id="second" class="col-xs-12 col-sm-6">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="row" {% if entry[0].sort %}data-name="{{entry[0].name}}"{% endif %} data-id="{% if entry[0].sort %}{{entry[0].sort}}{% else %}{% if entry.name %}{{entry.name}}{% else %}{{entry[0].name}}{% endif %}{% endif %}">
|
<div class="row" {% if entry[0].sort %}data-name="{{entry[0].name}}"{% endif %} data-id="{% if entry[0].sort %}{{entry[0].sort}}{% else %}{% if entry[0].format %}{{entry[0].format}}{% else %}{% if entry[0].rating %}{{entry[0].rating}}{% else %}{{entry[0].name}}{% endif %}{% endif %}{% endif %}">
|
||||||
<div class="col-xs-2 col-sm-2 col-md-1" align="left"><span class="badge">{{entry[1]}}</span></div>
|
<div class="col-xs-2 col-sm-2 col-md-1" align="left"><span class="badge">{{entry[1]}}</span></div>
|
||||||
<div class="col-xs-10 col-sm-10 col-md-11"><a id="list_{{loop.index0}}" href="{% if entry.format %}{{url_for('web.books_list', data=data, sort_param='stored', book_id=entry.format )}}{% else %}{{url_for('web.books_list', data=data, sort_param='stored', book_id=entry[0].id )}}{% endif %}">
|
<div class="col-xs-10 col-sm-10 col-md-11"><a id="list_{{loop.index0}}" href="{% if entry.format %}{{url_for('web.books_list', data=data, sort_param='stored', book_id=entry.format )}}{% else %}{{url_for('web.books_list', data=data, sort_param='stored', book_id=entry[0].id )}}{% endif %}">
|
||||||
{% if entry.name %}
|
{% if entry.name %}
|
||||||
|
40
cps/web.py
40
cps/web.py
@ -599,17 +599,29 @@ def render_series_books(page, book_id, order):
|
|||||||
|
|
||||||
|
|
||||||
def render_ratings_books(page, book_id, order):
|
def render_ratings_books(page, book_id, order):
|
||||||
name = calibre_db.session.query(db.Ratings).filter(db.Ratings.id == book_id).first()
|
if book_id == '-1':
|
||||||
entries, random, pagination = calibre_db.fill_indexpage(page, 0,
|
entries, random, pagination = calibre_db.fill_indexpage(page, 0,
|
||||||
db.Books,
|
db.Books,
|
||||||
db.Books.ratings.any(db.Ratings.id == book_id),
|
db.Books.ratings == None,
|
||||||
[order[0][0]],
|
[order[0][0]],
|
||||||
True, config.config_read_column)
|
True, config.config_read_column,
|
||||||
if name and name.rating <= 10:
|
db.books_series_link,
|
||||||
|
db.Books.id == db.books_series_link.c.book,
|
||||||
|
db.Series)
|
||||||
|
title = _(u"Rating: None")
|
||||||
|
rating = -1
|
||||||
|
else:
|
||||||
|
name = calibre_db.session.query(db.Ratings).filter(db.Ratings.id == book_id).first()
|
||||||
|
entries, random, pagination = calibre_db.fill_indexpage(page, 0,
|
||||||
|
db.Books,
|
||||||
|
db.Books.ratings.any(db.Ratings.id == book_id),
|
||||||
|
[order[0][0]],
|
||||||
|
True, config.config_read_column)
|
||||||
|
title = _(u"Rating: %(rating)s stars", rating=int(name.rating / 2))
|
||||||
|
rating = name.rating
|
||||||
|
if title and rating <= 10:
|
||||||
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
||||||
title=_(u"Rating: %(rating)s stars", rating=int(name.rating / 2)),
|
title=title, page="ratings", order=order[1])
|
||||||
page="ratings",
|
|
||||||
order=order[1])
|
|
||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
@ -1001,6 +1013,7 @@ def publisher_list():
|
|||||||
.count())
|
.count())
|
||||||
if no_publisher_count:
|
if no_publisher_count:
|
||||||
entries.append([db.Category(_("None"), "-1"), no_publisher_count])
|
entries.append([db.Category(_("None"), "-1"), no_publisher_count])
|
||||||
|
entries = sorted(entries, key=lambda x: x[0].name, reverse=not order_no)
|
||||||
char_list = generate_char_list(entries)
|
char_list = generate_char_list(entries)
|
||||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
||||||
title=_(u"Publishers"), page="publisherlist", data="publisher", order=order_no)
|
title=_(u"Publishers"), page="publisherlist", data="publisher", order=order_no)
|
||||||
@ -1030,6 +1043,7 @@ def series_list():
|
|||||||
.count())
|
.count())
|
||||||
if no_series_count:
|
if no_series_count:
|
||||||
entries.append([db.Category(_("None"), "-1"), no_series_count])
|
entries.append([db.Category(_("None"), "-1"), no_series_count])
|
||||||
|
entries = sorted(entries, key=lambda x: x[0].name, reverse=not order_no)
|
||||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
||||||
title=_(u"Series"), page="serieslist", data="series", order=order_no)
|
title=_(u"Series"), page="serieslist", data="series", order=order_no)
|
||||||
else:
|
else:
|
||||||
@ -1060,10 +1074,11 @@ def ratings_list():
|
|||||||
.group_by(text('books_ratings_link.rating')).order_by(order).all()
|
.group_by(text('books_ratings_link.rating')).order_by(order).all()
|
||||||
no_rating_count = (calibre_db.session.query(db.Books)
|
no_rating_count = (calibre_db.session.query(db.Books)
|
||||||
.outerjoin(db.books_ratings_link).outerjoin(db.Ratings)
|
.outerjoin(db.books_ratings_link).outerjoin(db.Ratings)
|
||||||
.filter(db.Ratings.name == None)
|
.filter(db.Ratings.rating == None)
|
||||||
.filter(calibre_db.common_filters())
|
.filter(calibre_db.common_filters())
|
||||||
.count())
|
.count())
|
||||||
entries.append([db.Category(_("None"), "-1"), no_rating_count])
|
entries.append([db.Category(_("None"), "-1", -1), no_rating_count])
|
||||||
|
entries = sorted(entries, key=lambda x: x[0].rating, reverse=not order_no)
|
||||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
|
||||||
title=_(u"Ratings list"), page="ratingslist", data="ratings", order=order_no)
|
title=_(u"Ratings list"), page="ratingslist", data="ratings", order=order_no)
|
||||||
else:
|
else:
|
||||||
@ -1130,6 +1145,7 @@ def category_list():
|
|||||||
.count())
|
.count())
|
||||||
if no_tag_count:
|
if no_tag_count:
|
||||||
entries.append([db.Category(_("None"), "-1"), no_tag_count])
|
entries.append([db.Category(_("None"), "-1"), no_tag_count])
|
||||||
|
entries = sorted(entries, key=lambda x: x[0].name, reverse=not order_no)
|
||||||
char_list = generate_char_list(entries)
|
char_list = generate_char_list(entries)
|
||||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
||||||
title=_(u"Categories"), page="catlist", data="category", order=order_no)
|
title=_(u"Categories"), page="catlist", data="category", order=order_no)
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user