57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import datetime
|
|
|
|
from flask import Flask
|
|
app = Flask(__name__)
|
|
|
|
def num2day(num):
|
|
match num:
|
|
case 1:
|
|
return "Monday"
|
|
case 2:
|
|
return "Tuesday"
|
|
case 3:
|
|
return "Wednesday"
|
|
case 4:
|
|
return "Thursday"
|
|
case 5:
|
|
return "Friday"
|
|
|
|
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)
|
|
workTime = workDatetime.strftime("%-I:%M%p")
|
|
return num2day(round(numDays+1)), workTime
|
|
|
|
|
|
|
|
def getTemplate():
|
|
now = datetime.datetime.now()
|
|
nowTime = now.strftime("%-I:%M%p")
|
|
nowDate = now.strftime("%x")
|
|
|
|
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
|
|
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 += "    a 90 minute football match,<br>"
|
|
template += f"        it would be the {round(yearPercent*90)}th minute.<br>"
|
|
template += "    a 40 hour work week,<br>"
|
|
template += f"        it would be {workTime} on {workDay}.<br>"
|
|
return template
|
|
|
|
#abbey road
|
|
#marathon
|
|
#the hobbit
|
|
|
|
@app.route("/")
|
|
def hello_world():
|
|
return getTemplate()
|