diff --git a/.gitignore b/.gitignore index 64dc10b..994e367 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .year-progress +__pycache__ diff --git a/year-progress.py b/year-progress.py index a5866b2..9ef174d 100644 --- a/year-progress.py +++ b/year-progress.py @@ -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}.") - -print("To put that into context:") - -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}.") +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}.
" + template += f"We are {round(yearPercent*100,2)}% of the way through {now.year}.
" + template += "To put that into context:
" + template += "If the year were
" + template += "    a 90 minute football match,
" + template += f"        it would be the {round(yearPercent*90)}th minute.
" + template += "    a 40 hour work week,
" + template += f"        it would be {workTime} on {workDay}.
" + return template #abbey road -#marathon world record +#marathon #the hobbit +@app.route("/") +def hello_world(): + return getTemplate()