Change couple more consistency improvements.

Change undo one simplification too far. Reasoning, the var is used later on in code, the natural eyeline is to look for the variable defined on the left above, and the declaration was hidden mid line due to walrus. Therefore, this makes it take longer to scan over code and slows down readability, i Bet this will be written about in some blog very soon.
Add ranking to scores on card
Change use new refactored overview cleaner
This commit is contained in:
JackDandy 2023-05-09 22:55:47 +01:00
parent 9f875601e4
commit da9a6a829c
3 changed files with 19 additions and 18 deletions

View file

@ -631,7 +631,7 @@ $(function() {
#end if
<div class="clearfix">
#if $use_ratings or $use_votes
<p>#if $use_ratings#<span class="rating">$this_show['rating']#if $re.search(r'^\d+(\.\d+)?$', (str($this_show['rating'])))#%</span>#end if##end if##if $use_votes#<i class="heart icon-glyph"></i><i>$this_show['votes'] $term_vote.lower()</i>#end if#</p>#slurp#
<p>#if $this_show.get('rank')#&#x23;$this_show.get('rank') #end if##if $use_ratings#<span class="rating">$this_show['rating']#if $re.search(r'^\d+(\.\d+)?$', (str($this_show['rating'])))#%</span>#end if##end if##if $use_votes#<i class="heart icon-glyph"></i><i>$this_show['votes'] $term_vote.lower()</i>#end if#</p>#slurp#
#else
<p>&nbsp;</p>
#end if

View file

@ -272,7 +272,7 @@ class TvdbAPIv4(TVInfoBase):
@staticmethod
def _check_resp(type_chk=list, data=None):
return isinstance(data, dict) and all(_k in data for _k in ('data', 'status')) \
and 'success' == data['status'] and isinstance(data['data'], type_chk)
and 'success' == data['status'] and isinstance(data['data'], type_chk) and bool(data['data'])
@staticmethod
def _next_page(resp, page):
@ -1102,10 +1102,11 @@ class TvdbAPIv4(TVInfoBase):
resp = self._get_show_data(ids[cur_tvinfo], cur_arg, direct_data=True)
type_chk = dict
else:
query = cur_arg % ids[cur_tvinfo]
resp = self.get_cached_or_url(
'search?meta=translations',
f's-v4-id-{cur_tvinfo}-{ids[cur_tvinfo]}', expire=self.search_cache_expire,
remote_id=(query := cur_arg % ids[cur_tvinfo]), query=query, type='series')
remote_id=query, query=query, type='series')
if self._check_resp(type_chk, resp):
if TVINFO_TVDB == cur_tvinfo:
@ -1121,21 +1122,19 @@ class TvdbAPIv4(TVInfoBase):
except (BaseException, Exception):
pass
if ids.get(TVINFO_TVDB_SLUG) and isinstance(ids.get(TVINFO_TVDB_SLUG), string_types):
if (resp := self.get_cached_or_url(
if ids.get(TVINFO_TVDB_SLUG) and isinstance(ids.get(TVINFO_TVDB_SLUG), string_types) \
and self._check_resp(dict, resp := self.get_cached_or_url(
f'/series/slug/{ids.get(TVINFO_TVDB_SLUG)}?meta=translations',
f's-id-{TVINFO_TVDB}-{ids[TVINFO_TVDB_SLUG]}', expire=self.search_cache_expire)) \
and self._check_resp(dict, resp) \
and ids.get(TVINFO_TVDB_SLUG).lower() == resp['data']['slug'].lower():
f's-id-{TVINFO_TVDB}-{ids[TVINFO_TVDB_SLUG]}', expire=self.search_cache_expire)):
if ids.get(TVINFO_TVDB_SLUG).lower() == resp['data']['slug'].lower():
results.extend(_make_result_dict(resp['data']))
if name:
for cur_name in ([name], name)[isinstance(name, list)]:
if (resp := self.get_cached_or_url(
if self._check_resp(list, resp := self.get_cached_or_url(
'search?meta=translations',
f's-v4-name-{cur_name}', expire=self.search_cache_expire,
query=cur_name, type='series')) \
and self._check_resp(list, resp):
query=cur_name, type='series')):
for cur_item in resp['data']:
results.extend(_make_result_dict(cur_item))
@ -1159,8 +1158,7 @@ class TvdbAPIv4(TVInfoBase):
result = []
page, cc = 0, 0
while 100 > page and cc < result_count:
if self._check_resp(list, resp := self._fetch_data('/series/filter', page=page, **kwargs)) \
and len(resp['data']):
if self._check_resp(list, resp := self._fetch_data('/series/filter', page=page, **kwargs)):
for cur_item in resp['data']:
cc += 1
if cc > result_count:

View file

@ -6070,6 +6070,8 @@ class AddShows(Home):
items = t.get_top_rated(year=top_year,
in_last_year=1 == datetime.date.today().month and 7 > datetime.date.today().day)
ranking = dict((val, idx+1) for idx, val in
enumerate(sorted([cur_show_info.rating for cur_show_info in items], reverse=True)))
oldest, newest, oldest_dt, newest_dt, dedupe = None, None, 9999999, 0, []
use_networks = False
parseinfo = dateutil.parser.parserinfo(dayfirst=False, yearfirst=True)
@ -6108,14 +6110,14 @@ class AddShows(Home):
ord_premiered=ord_premiered,
str_premiered=str_premiered,
started_past=started_past,
episode_overview=helpers.xhtml_escape(cur_show_info.overview[:250:]).strip('*').strip(),
episode_overview=self.clean_overview(cur_show_info),
episode_season=cur_show_info.season,
genres=', '.join(cur_show_info.genre_list)
or (cur_show_info.genre and (cur_show_info.genre.strip('|').replace('|', ', ')) or ''),
genres=(', '.join(cur_show_info.genre_list)
or (cur_show_info.genre and (cur_show_info.genre.strip('|').replace('|', ', ')) or '')
).lower(),
ids=ids,
images=images,
overview=(helpers.xhtml_escape(cur_show_info.overview[:250:]).strip('*').strip()
or 'No overview yet'),
overview=self.clean_overview(cur_show_info),
title=cur_show_info.seriesname,
language=language,
language_img=sickgear.MEMCACHE_FLAG_IMAGES.get(language, False),
@ -6125,6 +6127,7 @@ class AddShows(Home):
rating=False,
url_src_db=base_url % cur_show_info.id,
votes=cur_show_info.rating or 0,
rank=cur_show_info.rating and ranking.get(cur_show_info.rating) or 0,
))
except (BaseException, Exception):
pass