Bring back IRL section

This commit is contained in:
Alex Vanin 2018-11-25 15:35:50 +03:00
parent ad7c489a79
commit 11d00da468
3 changed files with 62 additions and 26 deletions

View file

@ -1,22 +1,26 @@
# fleast # fleast
Least-favourite twitch streamers here Least-favourite twitch streamers here
## Change-log ## Change Log
### 1.04 ### 1.5
- IRL section is back with IRL query
- Fixed bug when games with `&` symbol could not found correctly.
### 1.4
- Polished internal code and now cherrypy server configuration - Polished internal code and now cherrypy server configuration
is independent from nginx reverse proxy is independent from nginx reverse proxy
### 1.03 ### 1.3
- Fixed bug when VOD-streams appear in list of live streams - Fixed bug when VOD-streams appear in list of live streams
### 1.02 ### 1.2
- Fixed some typos in text - Fixed some typos in text
- Fixed bug with chinese language streams - Fixed bug with chinese language streams
- Fixed bug when 0 streams are found if game name contains whitespaces in the end - Fixed bug when 0 streams are found if game name contains whitespaces in the end
- Fixed bug with stream list if stream name contains '<' and '>' symbols - Fixed bug with stream list if stream name contains '<' and '>' symbols
### 1.01 ### 1.1
- Form data now saved between querries - Form data now saved between querries
### 1.00 ### 1.0
- Initial release - Initial release

17
main.py
View file

@ -2,11 +2,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import cherrypy import cherrypy
import json
from cherrypy.process.plugins import Daemonizer from cherrypy.process.plugins import Daemonizer
from twitch import TwitchClient from twitch import TwitchClient
ver = '1.04' ver = '1.5'
class FleastServer(object): class FleastServer(object):
@ -65,6 +64,9 @@ class FleastServer(object):
_opt_langs_=self.set_templ_lang('ru')) _opt_langs_=self.set_templ_lang('ru'))
game = game.rstrip() game = game.rstrip()
cherrypy.log('Getting game:"{}" language:{}'.format(game, lang)) cherrypy.log('Getting game:"{}" language:{}'.format(game, lang))
if game == "IRL":
data = self.client.get_irl_live_streams_v6(lang)
else:
data = self.client.get_live_streams(game.replace(' ', '%20').replace('&', '%26'), lang) data = self.client.get_live_streams(game.replace(' ', '%20').replace('&', '%26'), lang)
if data is None: if data is None:
@ -80,6 +82,17 @@ class FleastServer(object):
cherrypy.log('Found %d streams' % data['_total']) cherrypy.log('Found %d streams' % data['_total'])
if game == "IRL":
streams = sorted(data['streams'], key=lambda k: k['viewer_count'])
result_str = ''
irl_url = 'https://twitch.tv/{}'
for s in 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'
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:

View file

@ -134,3 +134,22 @@ class TwitchClient:
data['_total'] = len(data['streams']) data['_total'] = len(data['streams'])
return data return data
def get_irl_live_streams_v6(self, lang):
header, base = self.get_base('v6')
init_q_template = "{}/streams?language={}&first={}{}"
q_template = "{}/streams?language={}&first={}&after={}{}"
game_id = ''
irl_ids = ["509660", "509673", "509667", "509669", "509670", "509658",
"509672", "509671", "509664", "509663", "417752", "509659"]
for irl_id in irl_ids:
game_id += '&game_id={}'.format(irl_id)
result = {'_total': 0, 'streams': []}
data = self.do_q(init_q_template.format(base, lang, 100, game_id), header)
result['streams'].extend(data['data'])
while len(data['data']) == 100:
data = self.do_q(q_template.format(base, lang, 100, data['pagination']['cursor'], game_id), header)
result['streams'].extend(data['data'])
result['_total'] = len(result['streams'])
return result