From 73dc4874df3b523d88d15d3b94ea07137810909a Mon Sep 17 00:00:00 2001 From: Date: Sat, 14 Oct 2017 22:07:34 +0300 Subject: [PATCH] Version 1.01 Now form data is saved between queries --- src/main.py | 29 +++++++++++++++++++++++------ src/web/fl.html | 7 +++---- src/web/fl_template_lang.html | 13 +++++++++++++ src/web/fl_template_main.html | 7 +++---- 4 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 src/web/fl_template_lang.html diff --git a/src/main.py b/src/main.py index 4e70c93..c512de5 100755 --- a/src/main.py +++ b/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
Tell me more at https://twitter.com/alexvanin' 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(): diff --git a/src/web/fl.html b/src/web/fl.html index 0d2b813..e3d347a 100644 --- a/src/web/fl.html +++ b/src/web/fl.html @@ -17,8 +17,8 @@

Usage:

-

Write down a game name and choose language.
Name should be _exact_ name from Twitch i.e. csgo should be "Counter-Strike: Global Offensive"

-
+

Write the name of the game and select the language.
The name must _exactly_ match the name of the game on twitch.tv i.e. csgo must be "Counter-Strike: Global Offensive".

+ @@ -28,8 +28,7 @@ diff --git a/src/web/fl_template_lang.html b/src/web/fl_template_lang.html new file mode 100644 index 0000000..4e34fe2 --- /dev/null +++ b/src/web/fl_template_lang.html @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/web/fl_template_main.html b/src/web/fl_template_main.html index a617f2a..ac75b9d 100644 --- a/src/web/fl_template_main.html +++ b/src/web/fl_template_main.html @@ -16,8 +16,8 @@

Usage:

-

Write down a game name and choose language.
Name should be _exact_ name from Twitch i.e. csgo should be "Counter-Strike: Global Offensive"

- +

Write the name of the game and select the language.
The name must _exactly_ match the name of the game on twitch.tv i.e. csgo must be "Counter-Strike: Global Offensive".

+
@@ -27,8 +27,7 @@