From 543b9c7260ade1cc377ab6df886aad3bdb91d19f Mon Sep 17 00:00:00 2001 From: kleph Date: Thu, 20 Feb 2020 02:23:04 +0100 Subject: [PATCH] Configure time with URL --- beer.py | 14 ++++++++++---- {static => templates}/beer.html | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) rename {static => templates}/beer.html (97%) diff --git a/beer.py b/beer.py index 1c885fd..0bc8970 100755 --- a/beer.py +++ b/beer.py @@ -3,17 +3,23 @@ """ stupid countdown beer app to amuse my colleagues and collect buzzwords """ from flask import Flask +from flask import render_template # pylint: disable=invalid-name app = Flask(__name__) @app.route('/') -def index(): +@app.route('//') +def index(hours=None, minutes=None): """ main and only app """ - with open('static/beer.html') as html_file: - data = html_file.read() - return data + if not hours: + hours = 17 + if not minutes: + minutes = 0 + + data = render_template('beer.html', hours=hours, minutes=minutes) + return data def main(): diff --git a/static/beer.html b/templates/beer.html similarity index 97% rename from static/beer.html rename to templates/beer.html index 69af57c..207c63c 100644 --- a/static/beer.html +++ b/templates/beer.html @@ -52,7 +52,7 @@ var x = setInterval(function() { // var now = new Date().getTime(); var now = new Date().getTime(); var today = new Date(); - today.setHours(17, 00); + today.setHours( {{ hours }}, {{ minutes }}); var goal = today.getTime(); // Find the distance between now and the count down date