From 7fa5c6a7130756e1e35239662e7f61283f7143e3 Mon Sep 17 00:00:00 2001 From: Date: Fri, 13 Oct 2017 20:51:33 +0300 Subject: [PATCH] First release version --- .gitignore | 1 + src/main.py | 25 ++++++++++++++++--------- src/server.conf | 6 ------ src/web/favicon.ico | Bin 0 -> 1150 bytes src/web/fl.html | 8 +++++--- src/web/fl_template_main.html | 13 +++++++------ 6 files changed, 29 insertions(+), 24 deletions(-) delete mode 100644 src/server.conf create mode 100644 src/web/favicon.ico diff --git a/.gitignore b/.gitignore index 91a03f3..3147bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ src/__pycache__ *.swp src/.token +src/server.conf diff --git a/src/main.py b/src/main.py index d811a28..2dc005d 100755 --- a/src/main.py +++ b/src/main.py @@ -6,37 +6,43 @@ from twitch import TwitchClient import json import cherrypy +ver = '1.00' + + class FleastServer(object): def __init__(self): try: with open('.token', 'r') as reader: self.twitch_token = reader.read().strip() with open('./web/fl.html', 'r') as reader: - self.index = reader.read() + self.index_page = reader.read() with open('./web/fl_template_main.html', 'r') as reader: self.templ_main = reader.read() with open('./web/fl_template_stream.html', 'r') as reader: self.templ_stream = reader.read() + self.client = TwitchClient(self.twitch_token, freq = 1) except e: print("Cannot read token for twitch app or templates, abort.") exit(1) - self.client = TwitchClient(self.twitch_token, freq = 1) + @cherrypy.expose - def index(self): - return 'Hello World' + def index(self, game=None, lang=None): + return self.fleast(game, lang) @cherrypy.expose def fleast(self, game=None, lang=None): if game is None and lang is None: - return self.index + return self.index_page.format(_version_ = ver) + cherrypy.log('Getting game:"%s" language:%s' % (game, lang)) data = self.client.get_streams(game, lang) + if data is None: - return 'Internal Error' #Do Better + return 'Internal Error
Tell me more at https://twitter.com/alexvanin' if data['_total'] == 0: - return self.templ_main.format(data['_total'], '') + return self.templ_main.format( _stream_num_ = data['_total'], _stream_list_ = '', _version_ = ver) cherrypy.log('Found %d streams' % data['_total']) @@ -45,12 +51,13 @@ class FleastServer(object): for s in streams: 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(data['_total'], result_str) + + return self.templ_main.format(_stream_num_ = data['_total'], _game_name_ = game, _stream_list_ = result_str, _version_ = ver) def main(): server = FleastServer() - cherrypy.quickstart(server, '/','./server.conf') + cherrypy.quickstart(server, '/fleast', './server.conf') if __name__ == '__main__': diff --git a/src/server.conf b/src/server.conf deleted file mode 100644 index 342d24f..0000000 --- a/src/server.conf +++ /dev/null @@ -1,6 +0,0 @@ -[global] -server.socket_port: 8080 - -[/style.css] -tools.staticfile.on = True -tools.staticfile.filename = "/home/alexvanin/tmp/av/fleast/fleast/src/web/style.css" diff --git a/src/web/favicon.ico b/src/web/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..073cdb305754fac7ff653e0cb613638d4137b3d7 GIT binary patch literal 1150 zcmZQzU<5(|0R|wcz>vYhz#zuJz@P!dKp~(AL>x#lFaYI*xFHzK2NLTKd>eLHQ1JAB z5GL1e!$m*LAEbr_vOXA_l&~a653>2x(hoBSMkCvSj}23gPUF)vROSBvXJCNgpFlP; V{$bC+0Kzb_AM!vx5X01iXaE!ga_Im7 literal 0 HcmV?d00001 diff --git a/src/web/fl.html b/src/web/fl.html index bbec523..b1c019e 100644 --- a/src/web/fl.html +++ b/src/web/fl.html @@ -5,8 +5,9 @@ FLeast - + + @@ -16,7 +17,7 @@

Usage:

-

Write down a game name and choose language

+

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

@@ -40,7 +41,8 @@ diff --git a/src/web/fl_template_main.html b/src/web/fl_template_main.html index 71f3833..cca0114 100644 --- a/src/web/fl_template_main.html +++ b/src/web/fl_template_main.html @@ -5,8 +5,8 @@ FLeast - + @@ -16,7 +16,7 @@

Usage:

-

Write down a game name and choose language

+

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

@@ -25,7 +25,7 @@ - +