Version 1.01
Now form data is saved between queries
This commit is contained in:
parent
c4105cd814
commit
73dc4874df
4 changed files with 42 additions and 14 deletions
29
src/main.py
29
src/main.py
|
@ -7,7 +7,7 @@ import json
|
|||
import cherrypy
|
||||
from cherrypy.process.plugins import Daemonizer
|
||||
|
||||
ver = '1.00'
|
||||
ver = '1.01'
|
||||
|
||||
|
||||
class FleastServer(object):
|
||||
|
@ -21,11 +21,24 @@ class FleastServer(object):
|
|||
self.templ_main = reader.read()
|
||||
with open('./web/fl_template_stream.html', 'r') as reader:
|
||||
self.templ_stream = reader.read()
|
||||
with open('./web/fl_template_lang.html', 'r') as reader:
|
||||
self.templ_lang = reader.read().splitlines()
|
||||
self.client = TwitchClient(self.twitch_token, freq = 1)
|
||||
except e:
|
||||
except:
|
||||
print("Cannot read token for twitch app or templates, abort.")
|
||||
exit(1)
|
||||
|
||||
def set_templ_lang(self, lang):
|
||||
templ = ''
|
||||
end = False
|
||||
for l in self.templ_lang:
|
||||
if not end and 'option value="{}"'.format(lang) in l:
|
||||
templ += l.format('selected') + '\n'
|
||||
end = True
|
||||
continue
|
||||
templ += l.format(' ') + '\n'
|
||||
return templ.rstrip()
|
||||
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self, game=None, lang=None):
|
||||
|
@ -33,8 +46,8 @@ class FleastServer(object):
|
|||
|
||||
@cherrypy.expose
|
||||
def fleast(self, game=None, lang=None):
|
||||
if game is None and lang is None:
|
||||
return self.index_page.format(_version_ = ver)
|
||||
if game is None or game == '':
|
||||
return self.index_page.format(_version_ = ver, _opt_langs_ = self.set_templ_lang('ru'))
|
||||
|
||||
cherrypy.log('Getting game:"%s" language:%s' % (game, lang))
|
||||
data = self.client.get_streams(game, lang)
|
||||
|
@ -43,7 +56,9 @@ class FleastServer(object):
|
|||
return 'Internal Error<br>Tell me more at <a href="https://twitter.com/alexvanin">https://twitter.com/alexvanin</a>'
|
||||
|
||||
if data['_total'] == 0:
|
||||
return self.templ_main.format( _stream_num_ = data['_total'], _game_name_ = game, _stream_list_ = '', _version_ = ver)
|
||||
return self.templ_main.format( _stream_num_ = data['_total'], _game_name_ = game, \
|
||||
_opt_langs_ = self.set_templ_lang(lang), _stream_list_ = '', \
|
||||
_version_ = ver)
|
||||
|
||||
cherrypy.log('Found %d streams' % data['_total'])
|
||||
|
||||
|
@ -53,7 +68,9 @@ class FleastServer(object):
|
|||
result_str += self.templ_stream.format(s['channel']['url'], s['preview']['medium'],s['channel']['status'], \
|
||||
s['channel']['display_name'], s['viewers']) +'\n'
|
||||
|
||||
return self.templ_main.format(_stream_num_ = data['_total'], _game_name_ = game, _stream_list_ = result_str, _version_ = ver)
|
||||
return self.templ_main.format(_stream_num_ = data['_total'], _game_name_ = game, \
|
||||
_opt_langs_ = self.set_templ_lang(lang), _stream_list_ = result_str,\
|
||||
_version_ = ver)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<section id="pageContent">
|
||||
<article>
|
||||
<h2>Usage:</h2>
|
||||
<p>Write down a game name and choose language.<br>Name should be _exact_ name from Twitch i.e. csgo should be "Counter-Strike: Global Offensive" </p>
|
||||
<p>Write the name of the game and select the language.<br>The name must _exactly_ match the name of the game on twitch.tv i.e. csgo must be "Counter-Strike: Global Offensive".</p>
|
||||
<form method="get" action="./">
|
||||
<table class="Input">
|
||||
<tbody>
|
||||
|
@ -28,8 +28,7 @@
|
|||
<tr>
|
||||
<td><input name="game" type="text" maxlength="255" value=""/> </td>
|
||||
<td><select class="element select medium" name="lang">
|
||||
<option value="ru" selected="selected">ru</option>
|
||||
<option value="en">eng</option>
|
||||
{_opt_langs_}
|
||||
</select>
|
||||
</td>
|
||||
<td><input type="submit" value="Search" /></td>
|
||||
|
|
13
src/web/fl_template_lang.html
Normal file
13
src/web/fl_template_lang.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<option value="ru" {}>russian</option>
|
||||
<option value="en" {}>english</option>
|
||||
<option value="de" {}>german</option>
|
||||
<option value="zh" {}>chinese</option>
|
||||
<option value="fi" {}>finnish</option>
|
||||
<option value="fr" {}>french</option>
|
||||
<option value="it" {}>italian</option>
|
||||
<option value="ja" {}>japanese</option>
|
||||
<option value="ko" {}>korean</option>
|
||||
<option value="no" {}>norwegian</option>
|
||||
<option value="pl" {}>polish</option>
|
||||
<option value="es" {}>spanish</option>
|
||||
<option value="sv" {}>swedish</option>
|
|
@ -16,7 +16,7 @@
|
|||
<section id="pageContent">
|
||||
<article>
|
||||
<h2>Usage:</h2>
|
||||
<p>Write down a game name and choose language.<br>Name should be _exact_ name from Twitch i.e. csgo should be "Counter-Strike: Global Offensive" </p>
|
||||
<p>Write the name of the game and select the language.<br>The name must _exactly_ match the name of the game on twitch.tv i.e. csgo must be "Counter-Strike: Global Offensive".</p>
|
||||
<form method="get" action="./">
|
||||
<table class="Input">
|
||||
<tbody>
|
||||
|
@ -27,8 +27,7 @@
|
|||
<tr>
|
||||
<td><input name="game" type="text" maxlength="255" value="{_game_name_}"/> </td>
|
||||
<td><select class="element select medium" name="lang">
|
||||
<option value="ru" selected="selected">ru</option>
|
||||
<option value="en" >eng</option>
|
||||
{_opt_langs_}
|
||||
</select>
|
||||
</td>
|
||||
<td><input type="submit" value="Search" /></td>
|
||||
|
|
Loading…
Reference in a new issue