Add optional date param
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Tyler Perkins 2023-07-26 19:55:48 -04:00
parent bcfbbc8126
commit f2b1a9508a
1 changed files with 14 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from fastapi import FastAPI
import datetime
from fastapi import FastAPI, HTTPException
from datetime import datetime, date
import dateutil.parser
app = FastAPI()
@ -21,11 +22,20 @@ ben_franklin_virtues = {
@app.get("/")
async def virtue():
async def virtue(day: str = None):
"""
Get the virtue of the week
"""
current_week = datetime.date.today().isocalendar()[1]
if day is None:
current_date = date.today()
else:
try:
current_date = dateutil.parser.parse(day).date()
except:
raise HTTPException(status_code=400,
detail="Invalid date format, please provide a date in the month/day/year format.")
current_week = current_date.isocalendar()[1]
virtues = list(ben_franklin_virtues.keys())