First release version

This commit is contained in:
2017-10-13 20:51:33 +03:00
parent d4974c0e5c
commit 7fa5c6a713
6 changed files with 29 additions and 24 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
src/__pycache__ src/__pycache__
*.swp *.swp
src/.token src/.token
src/server.conf

View file

@ -6,37 +6,43 @@ from twitch import TwitchClient
import json import json
import cherrypy import cherrypy
ver = '1.00'
class FleastServer(object): class FleastServer(object):
def __init__(self): def __init__(self):
try: try:
with open('.token', 'r') as reader: with open('.token', 'r') as reader:
self.twitch_token = reader.read().strip() self.twitch_token = reader.read().strip()
with open('./web/fl.html', 'r') as reader: 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: with open('./web/fl_template_main.html', 'r') as reader:
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()
self.client = TwitchClient(self.twitch_token, freq = 1)
except e: except e:
print("Cannot read token for twitch app or templates, abort.") print("Cannot read token for twitch app or templates, abort.")
exit(1) exit(1)
self.client = TwitchClient(self.twitch_token, freq = 1)
@cherrypy.expose @cherrypy.expose
def index(self): def index(self, game=None, lang=None):
return 'Hello World' return self.fleast(game, lang)
@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 and lang is None:
return self.index return self.index_page.format(_version_ = ver)
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)
if data is None: if data is None:
return 'Internal Error' #Do Better 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(data['_total'], '') return self.templ_main.format( _stream_num_ = data['_total'], _stream_list_ = '', _version_ = ver)
cherrypy.log('Found %d streams' % data['_total']) cherrypy.log('Found %d streams' % data['_total'])
@ -45,12 +51,13 @@ class FleastServer(object):
for s in streams: for s in streams:
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(data['_total'], result_str)
return self.templ_main.format(_stream_num_ = data['_total'], _game_name_ = game, _stream_list_ = result_str, _version_ = ver)
def main(): def main():
server = FleastServer() server = FleastServer()
cherrypy.quickstart(server, '/','./server.conf') cherrypy.quickstart(server, '/fleast', './server.conf')
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -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"

BIN
src/web/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -5,8 +5,9 @@
<meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FLeast</title> <title>FLeast</title>
<meta name="description" content="Simple HTML5 Page layout template with header, footer, sidebar etc.">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/png">
</head> </head>
<body> <body>
@ -16,7 +17,7 @@
<section id="pageContent"> <section id="pageContent">
<article> <article>
<h2>Usage:</h2> <h2>Usage:</h2>
<p>Write down a game name and choose language </p> <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>
<form method="get" action="./fleast"> <form method="get" action="./fleast">
<table class="Input"> <table class="Input">
<tbody> <tbody>
@ -40,7 +41,8 @@
</section> </section>
<footer> <footer>
<p>Developed by Alex Vanin | <a href="https://twitter.com/AlexVanin" target="_blank">twitter</a> | <a href="https://github.com/AlexVanin/fleast" target="_blank">github</a> </p> <p>Developed by Alex Vanin | <a href="https://twitter.com/AlexVanin" target="_blank">twitter</a> | <a href="https://github.com/AlexVanin/fleast" target="_blank">github</a><br>
Version: {_version_} </p>
</footer> </footer>
</body> </body>

View file

@ -5,8 +5,8 @@
<meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FLeast</title> <title>FLeast</title>
<meta name="description" content="Simple HTML5 Page layout template with header, footer, sidebar etc.">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/png">
</head> </head>
<body> <body>
@ -16,7 +16,7 @@
<section id="pageContent"> <section id="pageContent">
<article> <article>
<h2>Usage:</h2> <h2>Usage:</h2>
<p>Write down a game name and choose language </p> <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>
<form method="get" action="./fleast"> <form method="get" action="./fleast">
<table class="Input"> <table class="Input">
<tbody> <tbody>
@ -25,7 +25,7 @@
<td><label>Language </label></td> <td><label>Language </label></td>
</tr> </tr>
<tr> <tr>
<td><input name="game" type="text" maxlength="255" value=""/> </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> <option value="ru" selected="selected">ru</option>
<option value="en" >eng</option> <option value="en" >eng</option>
@ -39,15 +39,16 @@
</p> </p>
</article> </article>
<artivle> <artivle>
<h2>Found {0} streams: </h2><br> <h2>Found {_stream_num_} streams: </h2><br>
<div class="container"> <div class="container">
{1} {_stream_list_}
</div> </div>
</article> </article>
</section> </section>
<footer> <footer>
<p>Developed by Alex Vanin | <a href="https://twitter.com/AlexVanin" target="_blank">twitter</a> | <a href="https://github.com/AlexVanin/fleast" target="_blank">github</a> </p> <p>Developed by Alex Vanin | <a href="https://twitter.com/AlexVanin" target="_blank">twitter</a> | <a href="https://github.com/AlexVanin/fleast" target="_blank">github</a><br>
Version: {_version_} </p>
</footer> </footer>
</body> </body>