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
|
import cherrypy
|
||||||
from cherrypy.process.plugins import Daemonizer
|
from cherrypy.process.plugins import Daemonizer
|
||||||
|
|
||||||
ver = '1.00'
|
ver = '1.01'
|
||||||
|
|
||||||
|
|
||||||
class FleastServer(object):
|
class FleastServer(object):
|
||||||
|
@ -21,11 +21,24 @@ class FleastServer(object):
|
||||||
self.templ_main = reader.read()
|
self.templ_main = reader.read()
|
||||||
with open('./web/fl_template_stream.html', 'r') as reader:
|
with open('./web/fl_template_stream.html', 'r') as reader:
|
||||||
self.templ_stream = reader.read()
|
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)
|
self.client = TwitchClient(self.twitch_token, freq = 1)
|
||||||
except e:
|
except:
|
||||||
print("Cannot read token for twitch app or templates, abort.")
|
print("Cannot read token for twitch app or templates, abort.")
|
||||||
exit(1)
|
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
|
@cherrypy.expose
|
||||||
def index(self, game=None, lang=None):
|
def index(self, game=None, lang=None):
|
||||||
|
@ -33,8 +46,8 @@ class FleastServer(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def fleast(self, game=None, lang=None):
|
def fleast(self, game=None, lang=None):
|
||||||
if game is None and lang is None:
|
if game is None or game == '':
|
||||||
return self.index_page.format(_version_ = ver)
|
return self.index_page.format(_version_ = ver, _opt_langs_ = self.set_templ_lang('ru'))
|
||||||
|
|
||||||
cherrypy.log('Getting game:"%s" language:%s' % (game, lang))
|
cherrypy.log('Getting game:"%s" language:%s' % (game, lang))
|
||||||
data = self.client.get_streams(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>'
|
return 'Internal Error<br>Tell me more at <a href="https://twitter.com/alexvanin">https://twitter.com/alexvanin</a>'
|
||||||
|
|
||||||
if data['_total'] == 0:
|
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'])
|
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'], \
|
result_str += self.templ_stream.format(s['channel']['url'], s['preview']['medium'],s['channel']['status'], \
|
||||||
s['channel']['display_name'], s['viewers']) +'\n'
|
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():
|
def main():
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
<section id="pageContent">
|
<section id="pageContent">
|
||||||
<article>
|
<article>
|
||||||
<h2>Usage:</h2>
|
<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="./">
|
<form method="get" action="./">
|
||||||
<table class="Input">
|
<table class="Input">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -28,8 +28,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><input name="game" type="text" maxlength="255" value=""/> </td>
|
<td><input name="game" type="text" maxlength="255" value=""/> </td>
|
||||||
<td><select class="element select medium" name="lang">
|
<td><select class="element select medium" name="lang">
|
||||||
<option value="ru" selected="selected">ru</option>
|
{_opt_langs_}
|
||||||
<option value="en">eng</option>
|
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td><input type="submit" value="Search" /></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,8 +16,8 @@
|
||||||
<section id="pageContent">
|
<section id="pageContent">
|
||||||
<article>
|
<article>
|
||||||
<h2>Usage:</h2>
|
<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="./">
|
<form method="get" action="./">
|
||||||
<table class="Input">
|
<table class="Input">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -27,8 +27,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><input name="game" type="text" maxlength="255" value="{_game_name_}"/> </td>
|
<td><input name="game" type="text" maxlength="255" value="{_game_name_}"/> </td>
|
||||||
<td><select class="element select medium" name="lang">
|
<td><select class="element select medium" name="lang">
|
||||||
<option value="ru" selected="selected">ru</option>
|
{_opt_langs_}
|
||||||
<option value="en" >eng</option>
|
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td><input type="submit" value="Search" /></td>
|
<td><input type="submit" value="Search" /></td>
|
||||||
|
|
Loading…
Reference in a new issue