diff --git a/src/main.py b/src/main.py
index 0d27c8c..d811a28 100755
--- a/src/main.py
+++ b/src/main.py
@@ -11,38 +11,46 @@ class FleastServer(object):
try:
with open('.token', 'r') as reader:
self.twitch_token = reader.read().strip()
- except:
- print("Cannot read token for twitch app, abort.")
+ with open('./web/fl.html', 'r') as reader:
+ self.index = 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()
+ 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'
@cherrypy.expose
- def fleast(self, game, lang):
+ def fleast(self, game=None, lang=None):
+ if game is None and lang is None:
+ return self.index
cherrypy.log('Getting game:"%s" language:%s' % (game, lang))
data = self.client.get_streams(game, lang)
if data is None:
- return 'Error!' #Do better
+ return 'Internal Error' #Do Better
+
if data['_total'] == 0:
- return 'No streams found' #Do better
+ return self.templ_main.format(data['_total'], '')
cherrypy.log('Found %d streams' % data['_total'])
- result = '
Test'
streams = sorted(data['streams'], key=lambda k: k['viewers'])
- count = 0
+ result_str = ''
for s in streams:
- result += '
{2} :: {3}
{4}
'.format( \
- s['channel']['url'], s['preview']['medium'], s['channel']['status'], \
- s['channel']['display_name'], s['viewers'])
- return result
+ 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)
def main():
- cherrypy.quickstart(FleastServer())
+ server = FleastServer()
+ cherrypy.quickstart(server, '/','./server.conf')
if __name__ == '__main__':
diff --git a/src/server.conf b/src/server.conf
index c480dbc..342d24f 100644
--- a/src/server.conf
+++ b/src/server.conf
@@ -1,2 +1,6 @@
[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/fl.html b/src/web/fl.html
new file mode 100644
index 0000000..bbec523
--- /dev/null
+++ b/src/web/fl.html
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+ FLeast
+
+
+
+
+
+
+
+
+ Usage:
+ Write down a game name and choose language
+
+
+
+
+
+
+
+
diff --git a/src/web/fl_template_main.html b/src/web/fl_template_main.html
new file mode 100644
index 0000000..71f3833
--- /dev/null
+++ b/src/web/fl_template_main.html
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+ FLeast
+
+
+
+
+
+
+
+
+ Usage:
+ Write down a game name and choose language
+
+
+
+
+ Found {0} streams:
+
+
+{1}
+
+
+
+
+
+
+
diff --git a/src/web/fl_template_stream.html b/src/web/fl_template_stream.html
new file mode 100644
index 0000000..7da688e
--- /dev/null
+++ b/src/web/fl_template_stream.html
@@ -0,0 +1,6 @@
+
+
+
{2}
+
{3}
+
:{4}
+
diff --git a/src/web/style.css b/src/web/style.css
new file mode 100644
index 0000000..960a020
--- /dev/null
+++ b/src/web/style.css
@@ -0,0 +1,99 @@
+body{background: #333333; line-height:1; font-family: arial;}
+h1{font-size: 25px;}h2{font-size: 21px;}h3{font-size: 18px;}h4{font-size: 16px;}
+table{border-collapse:collapse;border-spacing:0}
+hr{display:block;height:1px;border:0;border-top:1px solid #ccc;margin:1em 0;padding:0}
+
+#pageContent {
+ margin:0;padding:0;border:0;outline:0
+ max-width: 1000px;
+ margin: auto;
+ border: none;
+}
+
+#header {
+ padding:10px;
+
+}
+
+main {
+ float: left;
+ width: 60%;
+}
+aside {
+ float: right;
+ width: 30%;
+}
+article {
+ border-bottom: 2px dotted #999;
+ padding-bottom: 20px;
+ margin-bottom: 20px;
+}
+article h2 {
+ font-weight: normal;
+ margin-bottom: 12px;
+}
+article p {
+
+}
+main section {
+
+}
+footer {
+ background: #AEC6CF;
+ max-width: 1000px;
+ margin: auto;
+ clear: both;
+ text-align: right;
+}
+footer p {
+ padding: 20px;
+}
+
+aside > div {
+ margin: 10px auto;
+ background: #AEC6CF;
+ min-height: 100px;
+}
+
+body > section {
+ max-width: 1000px;
+ margin: auto;
+ padding: 30px 0px;
+ border-bottom: 1px solid #999;
+ color: #fff;
+}
+
+table.Input td, table.Input th {
+ border: 0px solid #AAAAAA;
+ padding: 2px 2px;
+}
+
+.container {
+ display: flex;
+ flex-wrap: wrap;
+ padding: 0px 0px 0px 10px
+}
+
+.inner {
+ overflow: auto;
+ word-wrap: break-word;
+ background-color: transparent;
+ width: 330px;
+ padding: 0px 0px 30px 0px
+}
+
+.strname {
+ font-weight: bold;
+}
+
+.struser {
+ font-size: 15px;
+ font-weight: bold;
+ color: #0f0
+}
+.strviews{
+ font-size: 15px;
+ font-weight: bold;
+ color: #f00
+}
+