First working version, prerelease
This commit is contained in:
parent
f6f3264e69
commit
d4974c0e5c
6 changed files with 231 additions and 13 deletions
32
src/main.py
32
src/main.py
|
@ -11,8 +11,14 @@ class FleastServer(object):
|
||||||
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()
|
||||||
except:
|
with open('./web/fl.html', 'r') as reader:
|
||||||
print("Cannot read token for twitch app, abort.")
|
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)
|
exit(1)
|
||||||
self.client = TwitchClient(self.twitch_token, freq = 1)
|
self.client = TwitchClient(self.twitch_token, freq = 1)
|
||||||
|
|
||||||
|
@ -21,28 +27,30 @@ class FleastServer(object):
|
||||||
return 'Hello World'
|
return 'Hello World'
|
||||||
|
|
||||||
@cherrypy.expose
|
@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))
|
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 'Error!' #Do better
|
return 'Internal Error' #Do Better
|
||||||
|
|
||||||
if data['_total'] == 0:
|
if data['_total'] == 0:
|
||||||
return 'No streams found' #Do better
|
return self.templ_main.format(data['_total'], '')
|
||||||
|
|
||||||
cherrypy.log('Found %d streams' % data['_total'])
|
cherrypy.log('Found %d streams' % data['_total'])
|
||||||
|
|
||||||
result = '<html><head><title>Test</title></head><body>'
|
|
||||||
streams = sorted(data['streams'], key=lambda k: k['viewers'])
|
streams = sorted(data['streams'], key=lambda k: k['viewers'])
|
||||||
count = 0
|
result_str = ''
|
||||||
for s in streams:
|
for s in streams:
|
||||||
result += '<a href="{0}"><img src="{1}"></a><br>{2} :: {3}<br>{4}<hr>'.format( \
|
result_str += self.templ_stream.format(s['channel']['url'], s['preview']['medium'],s['channel']['status'], \
|
||||||
s['channel']['url'], s['preview']['medium'], s['channel']['status'], \
|
s['channel']['display_name'], s['viewers']) +'\n'
|
||||||
s['channel']['display_name'], s['viewers'])
|
return self.templ_main.format(data['_total'], result_str)
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
cherrypy.quickstart(FleastServer())
|
server = FleastServer()
|
||||||
|
cherrypy.quickstart(server, '/','./server.conf')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,2 +1,6 @@
|
||||||
[global]
|
[global]
|
||||||
server.socket_port: 8080
|
server.socket_port: 8080
|
||||||
|
|
||||||
|
[/style.css]
|
||||||
|
tools.staticfile.on = True
|
||||||
|
tools.staticfile.filename = "/home/alexvanin/tmp/av/fleast/fleast/src/web/style.css"
|
||||||
|
|
47
src/web/fl.html
Normal file
47
src/web/fl.html
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en" class="no-js">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>FLeast</title>
|
||||||
|
<meta name="description" content="Simple HTML5 Page layout template with header, footer, sidebar etc.">
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<section id="header">
|
||||||
|
<strong><h1>FLeast - your least favorite streamers here</h1></strong>
|
||||||
|
</section>
|
||||||
|
<section id="pageContent">
|
||||||
|
<article>
|
||||||
|
<h2>Usage:</h2>
|
||||||
|
<p>Write down a game name and choose language </p>
|
||||||
|
<form method="get" action="./fleast">
|
||||||
|
<table class="Input">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><label>Game </label></td>
|
||||||
|
<td><label>Language </label></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><input name="game" type="text" maxlength="255" value=""/> </td>
|
||||||
|
<td><select class="element select medium" name="lang">
|
||||||
|
<option value="ru" selected="selected">ru</option>
|
||||||
|
<option value="en">eng</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td><input type="submit" value="Search" /></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
<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>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
54
src/web/fl_template_main.html
Normal file
54
src/web/fl_template_main.html
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en" class="no-js">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>FLeast</title>
|
||||||
|
<meta name="description" content="Simple HTML5 Page layout template with header, footer, sidebar etc.">
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<section id="header">
|
||||||
|
<strong><h1>FLeast - your least favorite streamers here</h1></strong>
|
||||||
|
</section>
|
||||||
|
<section id="pageContent">
|
||||||
|
<article>
|
||||||
|
<h2>Usage:</h2>
|
||||||
|
<p>Write down a game name and choose language </p>
|
||||||
|
<form method="get" action="./fleast">
|
||||||
|
<table class="Input">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><label>Game </label></td>
|
||||||
|
<td><label>Language </label></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><input name="game" type="text" maxlength="255" value=""/> </td>
|
||||||
|
<td><select class="element select medium" name="lang">
|
||||||
|
<option value="ru" selected="selected">ru</option>
|
||||||
|
<option value="en" >eng</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td><input type="submit" value="Search" /></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
</article>
|
||||||
|
<artivle>
|
||||||
|
<h2>Found {0} streams: </h2><br>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
{1}
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
|
<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>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
6
src/web/fl_template_stream.html
Normal file
6
src/web/fl_template_stream.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<div class="inner">
|
||||||
|
<a href="{0}" target="_blank"><img src={1}></a><br>
|
||||||
|
<div class="strname">{2}</div>
|
||||||
|
<span class="struser">{3}</span>
|
||||||
|
<span class="strviews"> :{4}</span>
|
||||||
|
</div>
|
99
src/web/style.css
Normal file
99
src/web/style.css
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue