From b9eb73b77d33c79b6c4685431e211a6370ed06a3 Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Mon, 3 Jul 2017 21:37:19 +0200 Subject: [PATCH] #7 and #3 In the overview, a column is added. The time remaining a player can play. --- nfgame.py | 21 +++++++++++++++++++-- templates/highscores.html | 35 +++++++++++++++++++++++++++++++++++ templates/overview.html | 4 ++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 templates/highscores.html diff --git a/nfgame.py b/nfgame.py index 4b5aa1d..2f04db7 100644 --- a/nfgame.py +++ b/nfgame.py @@ -72,6 +72,7 @@ def index(): user = {} tags = app.config['TAGS'] + timeremaining = {} for entry in entries: if entry['tags'] == None: @@ -87,7 +88,23 @@ def index(): if found_tag == tag: user[entry['id']][tag] = 'Found' - return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user, type='Current players', refresh=app.config['REFRESH_TIME']) + '''Calculate time remaining''' + starttime = datetime.strptime(entry['starttime'], "%Y-%m-%d %H:%M:%S") + endtime = starttime + timedelta(seconds=int(app.config['MAX_TIME'])) + playtime = endtime - datetime.now() + if datetime.now() > endtime: + timeremaining[entry['id']] = "Time's up" + else: + hours = playtime.seconds / 3600 + minutes = (playtime.seconds - (hours * 3600)) / 60 + seconds = playtime.seconds - (minutes * 60) + if len(str(minutes)) == 1: + minutes = '0' + str(minutes) + if len(str(seconds)) == 1: + seconds = '0' + str(seconds) + timeremaining[entry['id']] = str(hours) + ":" + str(minutes) + ":" + str(seconds) + + return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user, type='Current players', refresh=app.config['REFRESH_TIME'], timeremaining=timeremaining) @app.route('/highscores') def highscores(): @@ -119,7 +136,7 @@ def highscores(): if found_tag == tag: user[entry['id']][tag] = 'Found' - return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user, type='Highscores', refresh=app.config['REFRESH_TIME']) + return render_template('highscores.html', entries=entries, tags=app.config['TAGS'], user=user, type='Highscores', refresh=app.config['REFRESH_TIME']) @app.route('/newuser/', methods=['GET', 'POST']) @app.route('/newuser//', methods=['GET', 'POST']) diff --git a/templates/highscores.html b/templates/highscores.html new file mode 100644 index 0000000..8f4f148 --- /dev/null +++ b/templates/highscores.html @@ -0,0 +1,35 @@ +{% extends "layout-overview.html" %} +{% block body %} +

{{ type }}

+ +
+
+ + + + + + + + + + + {% for entry in entries %} + + + + + {% endfor %} + +
NameDuration
{{ entry.username }} + {% if entry.duration == '99:99:99' %} + No time yet + {% else %} + {{ entry.duration }} + {% endif %} +
+ +
+
+{% endblock %} + diff --git a/templates/overview.html b/templates/overview.html index 0693861..8613f6f 100644 --- a/templates/overview.html +++ b/templates/overview.html @@ -14,6 +14,7 @@ {{ tags.get(tag) }} {% endfor %} Duration + Time remaining @@ -36,6 +37,9 @@ {{ entry.duration }} {% endif %} + + {{ timeremaining[entry.id] }} + {% endfor %}