From 647c29c2c7709f51f504bcf19d47dbb83106d468 Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Sun, 2 Jul 2017 21:13:11 +0200 Subject: [PATCH] #7 Main overview now only shows the current active users in the time window set by the config file. --- nfgame.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nfgame.py b/nfgame.py index 3599e0d..f758c5b 100644 --- a/nfgame.py +++ b/nfgame.py @@ -4,7 +4,7 @@ import sqlite3 from flask import Flask, request, g, redirect, url_for, abort, \ render_template, flash, session import random -from datetime import datetime +from datetime import datetime, timedelta # create our little application :) app = Flask(__name__) @@ -60,8 +60,12 @@ def close_db(error): @app.route('/') def index(): + """Calculate starttime""" + now = datetime.now() - timedelta(seconds=int(app.config['MAX_TIME'])) + maxstarttime = datetime.strptime((str(now.year)+"-"+str(now.month)+"-"+str(now.day)+" "+str(now.hour)+":"+str(now.minute)+":"+str(now.second)), "%Y-%m-%d %H:%M:%S") + db = get_db() - cur = db.execute('select * from score order by duration asc') + cur = db.execute('select * from score where starttime > ? order by duration asc', [maxstarttime]) entries = cur.fetchall() user = {}