because controversial is either 0 or 1 sort it by dislikes

This commit is contained in:
bassdart 2019-03-17 01:55:56 +01:00
parent 75f286828e
commit 822f4faff2

View file

@ -706,9 +706,16 @@ def sortTitlesBy(limit, sort, start):
modus = channel modus = channel
else: else:
modus = 'all' modus = 'all'
# sort by negated count first and then by title in lexical order.
if mycount != "" and mycount == "controversial":
# controversial is either 0 or 1 so it does not makes sense to sort upon it
# instead sort videos considered controversial by dislikes
# change controversial in videos.json to a float?
result = sorted(result, key = lambda i: (-1*float(i['dislikes']), i['title']))
else:
# If count would'nt be negated one had to use reverse=true # If count would'nt be negated one had to use reverse=true
# But then the second sorting, by title would be reversed also # but then the second sorting, by title would be reversed also
# sort by negated count first and then by title in lexical order.
result = sorted(result, key = lambda i: (-1*float(i[mycount]), i['title'])) result = sorted(result, key = lambda i: (-1*float(i[mycount]), i['title']))
# itemgetter, should be faster (hm, but does'nt work: ValueError: could not convert string to float: pcount) # itemgetter, should be faster (hm, but does'nt work: ValueError: could not convert string to float: pcount)
# importing "operator" for implementing itemgetter # importing "operator" for implementing itemgetter