From b37827b91d190e5d8b989f49dba65b784f5ef783 Mon Sep 17 00:00:00 2001 From: alexvanin Date: Sat, 16 May 2020 16:04:34 +0300 Subject: [PATCH] api: Fix bug when "unique_streams" returned incorrect dict --- main.py | 11 +++-------- twitch.py | 3 ++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 6af783c..a453869 100755 --- a/main.py +++ b/main.py @@ -84,21 +84,16 @@ class FleastServer(object): _version_=ver) cherrypy.log('Found %d streams' % data['_total']) - - uniq_streams = [] - streams = sorted(data['streams'], key=lambda k: k['viewer_count']) result_str = '' irl_url = 'https://twitch.tv/{}' - for s in streams: - if s['user_name'] not in uniq_streams: - uniq_streams.append(s['user_name']) - result_str += self.templ_stream.format(irl_url.format(s['user_name']), + for s in data['streams']: + result_str += self.templ_stream.format(irl_url.format(s['user_name']), s['thumbnail_url'].format(width=320, height=180), self.to_html(s['title']), s['user_name'], s['viewer_count']) + '\n' - return self.templ_main.format(_stream_num_=len(streams), + return self.templ_main.format(_stream_num_=len(data['streams']), _game_name_=game, _opt_langs_=self.set_templ_lang(lang), _stream_list_=result_str, diff --git a/twitch.py b/twitch.py index 48fca2b..a473ce6 100644 --- a/twitch.py +++ b/twitch.py @@ -188,9 +188,10 @@ class TwitchClient: def unique_streams_v6(self, result): uniq_streams = [] streams = sorted(result['streams'], key=lambda k: k['viewer_count']) + result['streams']=[] for s in streams: if s['user_name'] not in uniq_streams: uniq_streams.append(s['user_name']) - result['streams'] = uniq_streams + result['streams'].append(s) result['_total'] = len(result['streams']) return result