Fixed bug when there could be copies in IRL query answer

This commit is contained in:
Alex Vanin 2018-12-01 20:37:05 +03:00
parent a49e0aed68
commit 95ccc3766b
2 changed files with 14 additions and 7 deletions

View file

@ -2,6 +2,9 @@
Least-favourite twitch streamers here Least-favourite twitch streamers here
## Change Log ## Change Log
### 1.6
- Fixed bug, when IRL query could contain several copies of one stream
### 1.5 ### 1.5
- IRL section is back with IRL query - IRL section is back with IRL query
- Fixed bug when games with `&` symbol could not found correctly. - Fixed bug when games with `&` symbol could not found correctly.

View file

@ -5,7 +5,7 @@ import cherrypy
from cherrypy.process.plugins import Daemonizer from cherrypy.process.plugins import Daemonizer
from twitch import TwitchClient from twitch import TwitchClient
ver = '1.5' ver = '1.6'
class FleastServer(object): class FleastServer(object):
@ -83,16 +83,20 @@ class FleastServer(object):
cherrypy.log('Found %d streams' % data['_total']) cherrypy.log('Found %d streams' % data['_total'])
if game == "IRL": if game == "IRL":
uniq_streams = []
streams = sorted(data['streams'], key=lambda k: k['viewer_count']) streams = sorted(data['streams'], key=lambda k: k['viewer_count'])
result_str = '' result_str = ''
irl_url = 'https://twitch.tv/{}' irl_url = 'https://twitch.tv/{}'
for s in streams: 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']), result_str += self.templ_stream.format(irl_url.format(s['user_name']),
s['thumbnail_url'].format(width=320, height=180), s['thumbnail_url'].format(width=320, height=180),
self.to_html(s['title']), self.to_html(s['title']),
s['user_name'], s['user_name'],
s['viewer_count']) + '\n' s['viewer_count']) + '\n'
else: else:
streams = sorted(data['streams'], key=lambda k: k['viewers']) streams = sorted(data['streams'], key=lambda k: k['viewers'])
result_str = '' result_str = ''
for s in streams: for s in streams:
@ -111,7 +115,7 @@ class FleastServer(object):
def main(): def main():
server = FleastServer() server = FleastServer()
d = Daemonizer(cherrypy.engine).subscribe() # d = Daemonizer(cherrypy.engine).subscribe()
cherrypy.quickstart(server, '/', './server.conf') cherrypy.quickstart(server, '/', './server.conf')