[2024-08-10] Add CSS, templates, and marathon comparison

This commit is contained in:
Andrew Conlin 2024-08-10 21:26:41 +01:00
parent fb1bde579d
commit 5b717ddf11
3 changed files with 124 additions and 19 deletions

View file

@ -1,6 +1,7 @@
import datetime
import math
from flask import Flask
from flask import Flask, render_template, url_for
app = Flask(__name__)
def num2day(num):
@ -19,38 +20,41 @@ def num2day(num):
def workWeek(yearPercent):
totalNumHours = 40*yearPercent
numDays = totalNumHours/8
hoursIntoDay = (numDays - round(numDays))*8
minutesIntoDay = round((hoursIntoDay - round(hoursIntoDay))*60)
workDatetime = datetime.datetime(year=1970,month=1,day=1,hour=round(hoursIntoDay)+9,minute=minutesIntoDay)
hoursIntoDay = (numDays - math.floor(numDays))*8
minutesIntoDay = round((hoursIntoDay - math.floor(hoursIntoDay))*60)
workDatetime = datetime.datetime(year=1970,month=1,day=1,hour=math.floor(hoursIntoDay)+9,minute=minutesIntoDay)
workTime = workDatetime.strftime("%-I:%M%p")
return num2day(round(numDays+1)), workTime
return num2day(math.floor(numDays+1)), workTime
def getTemplate():
now = datetime.datetime.now()
nowTime = now.strftime("%-I:%M%p")
nowDate = now.strftime("%x")
nowDate = now.strftime("%A") + " " + now.strftime("%-d") + " " + now.strftime("%B")
delta = now - datetime.datetime(day=1,month=1,year=now.year)
totalDays = datetime.datetime(day=1,month=1,year=now.year+1) - datetime.datetime(day=1,month=1,year=now.year)
yearPercent = delta/totalDays
footballMinute = math.floor(yearPercent*90)
workDay, workTime = workWeek(yearPercent)
template = f"It is currently {nowTime}, on {nowDate}.<br>"
template += f"We are {round(yearPercent*100,2)}% of the way through {now.year}.<br>"
template += "To put that into context:<br>"
template += "If the year were<br>"
template += "&nbsp&nbsp&nbsp&nbspa 90 minute football match,<br>"
template += f"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspit would be the {round(yearPercent*90)}th minute.<br>"
template += "&nbsp&nbsp&nbsp&nbspa 40 hour work week,<br>"
template += f"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspit would be {workTime} on {workDay}.<br>"
return template
marathonMile = 26.2 - math.floor(yearPercent*26.2)
return now.year, nowTime, nowDate, round(yearPercent*100,2), footballMinute, workDay, workTime, marathonMile
#abbey road
#marathon
#the hobbit
@app.route("/")
def hello_world():
return getTemplate()
year, nowTime, nowDate, yearPercent, footballMinute, workDay, workTime, marathonMile = getTemplate()
cssPath = url_for('static', filename='style.css')
return render_template("index.html",\
cssPath=cssPath,\
year=year,\
nowTime=nowTime,\
nowDate=nowDate,\
yearPercent=yearPercent,\
footballMinute=footballMinute,\
workDay=workDay,\
workTime=workTime,\
marathonMile=marathonMile)