diff --git a/templates/init.html b/templates/init.html new file mode 100644 index 0000000..a22f1f4 --- /dev/null +++ b/templates/init.html @@ -0,0 +1,18 @@ + +
+ + diff --git a/year-progress.py b/year-progress.py index 165b1d4..088148c 100644 --- a/year-progress.py +++ b/year-progress.py @@ -1,7 +1,7 @@ import datetime import math -from flask import Flask, render_template, url_for +from flask import Flask, render_template, url_for, request app = Flask(__name__) def num2day(num): @@ -136,8 +136,8 @@ def getHomoSapiens(yearPercent): else: return f"Homo Sapiens have been around for ~{-math.floor(yearsUntilHumans)} years." -def getTemplate(): - now = datetime.datetime.now() +def getTemplate(timestamp): + now = datetime.datetime.fromtimestamp(timestamp) nowTime = now.strftime("%-I:%M%p") nowDate = now.strftime("%A") + " " + now.strftime("%-d") + " " + now.strftime("%B") @@ -155,10 +155,9 @@ def getTemplate(): return now.year, nowTime, nowDate, round(yearPercent*100,2), footballMinute, workDay, workTime, marathonMile, abbeyRoadSong, hobbitChapter, lat, long, homoSapiens -@app.route("/") -def index(): - year, nowTime, nowDate, yearPercent, footballMinute, workDay, workTime, marathonMile, abbeyRoadSong, hobbitChapter, lat, long, homoSapiens = getTemplate() - cssPath = url_for('static', filename='style.css') +def index(timestamp): + year, nowTime, nowDate, yearPercent, footballMinute, workDay, workTime, marathonMile, abbeyRoadSong, hobbitChapter, lat, long, homoSapiens = getTemplate(timestamp) + cssPath = url_for("static", filename="style.css") return render_template("index.html",\ cssPath=cssPath,\ year=year,\ @@ -174,3 +173,12 @@ def index(): lat=lat,\ long=long,\ homoSapiens=homoSapiens) + +@app.route("/", methods=["GET","POST"]) +def init(): + if request.method == "POST": + timestamp = int(request.values.get('timestamp')) + return index(timestamp) + else: + return render_template("init.html") +