[2024-08-10] Flask app, serving the text-based output as a web app

This commit is contained in:
Andrew Conlin 2024-08-10 19:17:26 +01:00
parent 1e7dc22074
commit fb1bde579d
2 changed files with 31 additions and 20 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.year-progress
__pycache__

View File

@ -1,5 +1,8 @@
import datetime
from flask import Flask
app = Flask(__name__)
def num2day(num):
match num:
case 1:
@ -18,29 +21,36 @@ def workWeek(yearPercent):
numDays = totalNumHours/8
hoursIntoDay = (numDays - round(numDays))*8
minutesIntoDay = round((hoursIntoDay - round(hoursIntoDay))*60)
return num2day(round(numDays+1)), round(hoursIntoDay)+9, minutesIntoDay
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
currentTime = datetime.datetime.now()
print (f"It is currently {currentTime.hour}:{currentTime.minute}, on {currentTime.day}/{currentTime.month}/{currentTime.year}.")
delta = currentTime - datetime.datetime(day=1,month=1,year=currentTime.year)
total_days = datetime.datetime(day=1,month=1,year=currentTime.year+1) - datetime.datetime(day=1,month=1,year=currentTime.year)
yearPercent = delta/total_days
print(f"We are {round(yearPercent*100,2)}% of the way through {currentTime.year}.")
def getTemplate():
now = datetime.datetime.now()
nowTime = now.strftime("%-I:%M%p")
nowDate = now.strftime("%x")
print("To put that into context:")
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)
print("If the year were")
print(" a 90 minute football match,")
print(f" it would be the {round(yearPercent*90)}th minute.")
day, hours, minutes = workWeek(yearPercent)
print(" a 40 hour work week,")
print(f" it would be {hours}:{minutes} on {day}.")
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 += "&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
#abbey road
#marathon world record
#marathon
#the hobbit
@app.route("/")
def hello_world():
return getTemplate()