summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorraylu <raylu@gridium.com>2013-05-03 03:41:50 -0700
committerraylu <raylu@gridium.com>2013-10-19 18:21:46 -0700
commit224f66a77aa3afa5e06daec656ae97f6e31e0592 (patch)
treef36843c32143c401ec1c6dccd502cddcbba6017c /web
downloadykill-224f66a77aa3afa5e06daec656ae97f6e31e0592.tar.xz
start over
Diffstat (limited to 'web')
-rwxr-xr-xweb/server.py57
-rw-r--r--web/static/css/base.less37
-rw-r--r--web/templates/base.html18
-rw-r--r--web/templates/home.html30
4 files changed, 142 insertions, 0 deletions
diff --git a/web/server.py b/web/server.py
new file mode 100755
index 0000000..01475c1
--- /dev/null
+++ b/web/server.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+
+import json
+from lesscss import lessc
+import tornado.gen
+import tornado.httpclient
+import tornado.ioloop
+import tornado.web
+import operator
+import os
+
+import config
+
+class BaseHandler(tornado.web.RequestHandler):
+ def render(self, *args, **kwargs):
+ kwargs['host'] = config.web.host
+ return super(BaseHandler, self).render(*args, **kwargs)
+
+ def render_string(self, *args, **kwargs):
+ s = super(BaseHandler, self).render_string(*args, **kwargs)
+ return s.replace(b'\n', b'') # this is like Django's {% spaceless %}
+
+class MainHandler(BaseHandler):
+ @tornado.web.asynchronous
+ @tornado.gen.coroutine
+ def get(self):
+ http_client = tornado.httpclient.AsyncHTTPClient()
+ kills_url = 'https://zkillboard.com/api/kills/corporationID/98182803/limit/1'
+ losses_url = 'https://zkillboard.com/api/losses/corporationID/98182803/limit/1'
+ kills_res, losses_res = yield [http_client.fetch(kills_url), http_client.fetch(losses_url)]
+ kills = json.loads(kills_res.body.decode('utf-8'))
+ losses = json.loads(losses_res.body.decode('utf-8'))
+ kills = sorted(kills + losses, key=operator.itemgetter('killTime'), reverse=True)
+ self.render('home.html', kills=kills)
+
+
+class CSSHandler(tornado.web.RequestHandler):
+ def get(self, css_path):
+ css_path = os.path.join(os.path.dirname(__file__), 'static', css_path) + '.less'
+ with open(css_path, 'r') as f:
+ self.set_header('Content-Type', 'text/css')
+ css = lessc.compile(f.read())
+ self.write(css)
+
+if __name__ == '__main__':
+ tornado.web.Application(
+ handlers=[
+ (r'/', MainHandler),
+ (r"/(css/.+)\.css", CSSHandler),
+ ],
+ template_path=os.path.join(os.path.dirname(__file__), 'templates'),
+ static_path=os.path.join(os.path.dirname(__file__), 'static'),
+ cookie_secret=config.web.cookie_secret,
+ debug=True,
+ ).listen(config.web.port)
+ print('Listening on :%d' % config.web.port)
+ tornado.ioloop.IOLoop.instance().start()
diff --git a/web/static/css/base.less b/web/static/css/base.less
new file mode 100644
index 0000000..714d5ab
--- /dev/null
+++ b/web/static/css/base.less
@@ -0,0 +1,37 @@
+* {
+ box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+}
+
+body {
+ margin: 0;
+ padding: 0;
+ height: 100%;
+ background: #000;
+ color: #ddd;
+ font-family: sans-serif;
+}
+
+a {
+ text-decoration: none;
+ color: #dde;
+}
+
+form {
+ input {
+ background: #fff;
+ border: 1px solid #cdd;
+ padding: 5px 10px;
+ }
+}
+
+.clear {
+ clear: both;
+}
+
+#wrapper {
+ width: 900px;
+ margin: 50px auto;
+ background: #111;
+}
diff --git a/web/templates/base.html b/web/templates/base.html
new file mode 100644
index 0000000..afd3c68
--- /dev/null
+++ b/web/templates/base.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link rel="stylesheet" type="text/css" href="/css/base.css" />
+ <script src="//ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools.js"></script>
+</head>
+<body>
+ <div id="wrapper">
+ <div id="topbar">
+ <div id="title"></div>
+ <div id="nav">
+ </div>
+ </div>
+
+ {% block main %}{% end %}
+ </div>
+</body>
+</html>
diff --git a/web/templates/home.html b/web/templates/home.html
new file mode 100644
index 0000000..6d4f69c
--- /dev/null
+++ b/web/templates/home.html
@@ -0,0 +1,30 @@
+{% extends "base.html" %}
+
+{% block main %}
+
+<div class="kill_list">
+ {% for kill in kills %}
+ <a href="/kill/{{ kill['killID'] }}">
+ {{ kill['killTime'] }}
+ {{ kill['solarSystemID'] }}
+ <img src="//image.eveonline.com/Type/{{ kill['victim']['shipTypeID'] }}_64.png">
+ <img src="//image.eveonline.com/Character/{{ kill['victim']['characterID'] }}_64.jpg">
+ <img src="//image.eveonline.com/Corporation/{{ kill['victim']['corporationID'] }}_64.png">
+ <img src="//image.eveonline.com/Alliance/{{ kill['victim']['allianceID'] }}_64.png">
+ {{ kill['victim']['characterName'] }}
+ {{ kill['victim']['corporationName'] }}
+ {{ kill['victim']['allianceName'] }}
+ {% for attacker in kill['attackers'] %}
+ {% if attacker['finalBlow'] %}
+ {% set killer = attacker %}
+ {% break %}
+ {% end %}
+ {% end %}
+ {{ killer['characterName'] }}
+ {{ killer['corporationName'] }}
+ {{ killer['allianceName'] }}
+ </a>
+ {% end %}
+</div>
+
+{% end %}