-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
52 lines (42 loc) · 1.49 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import json
import os
from bottle import route, run, template, static_file, request
from redis import Redis
import redis
if "REDIS_URL" in os.environ:
redis = redis.from_url(os.environ.get("REDIS_URL"))
else:
redis = Redis(host='redis', port=6379)
@route('/kill', method='POST')
def kill():
redis.incr('kills')
if request.forms.get("name"):
user = request.forms.get("name")
# print user
redis.incr(user)
return template('<b>Flies killed: {{num_killed}}</b>!', num_killed=redis.get(user))
else:
return template('<b>Flies killed: {{num_killed}}</b>!', num_killed=redis.get('kills'))
@route('/kill/<user>')
def user_kill(user):
redis.incr('kills')
redis.incr(user)
return template('<b>Flies killed: {{num_killed}}</b>!', num_killed=redis.get(user))
@route('/total')
def total():
return {"total": redis.get('kills')}
@route('/scoreboard')
def scoreboard():
keys = redis.keys()
l = [{"name":k, "score":int(redis.get(k))} for k in keys if k != "kills"]
return json.dumps(sorted(l, key=lambda x: x['score'], reverse=True))
@route('/')
def index():
return template('home.tpl', deaths=redis.get('kills'))
@route('/bower_components/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root='bower_components')
@route('/static/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root='static')
run(host='0.0.0.0', port=int(os.environ.get("PORT", 5000)), debug=True, reloader=True)