Add optional date param
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
bcfbbc8126
commit
f2b1a9508a
18
src/main.py
18
src/main.py
|
@ -1,5 +1,6 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI, HTTPException
|
||||||
import datetime
|
from datetime import datetime, date
|
||||||
|
import dateutil.parser
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
@ -21,11 +22,20 @@ ben_franklin_virtues = {
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def virtue():
|
async def virtue(day: str = None):
|
||||||
"""
|
"""
|
||||||
Get the virtue of the week
|
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())
|
virtues = list(ben_franklin_virtues.keys())
|
||||||
|
|
||||||
|
|
Reference in New Issue