add days and units to api server (#150)

* add days and units to api server

* add more stuff

* fix more
This commit is contained in:
Adil Hafeez 2024-10-08 18:14:06 -07:00 committed by GitHub
parent e08d406be5
commit 3b26b16fc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -19,6 +19,8 @@ async def healthz():
class WeatherRequest(BaseModel):
city: str
days: int = 7
units: str = "Farenheit"
@app.post("/weather")
@ -27,17 +29,22 @@ async def weather(req: WeatherRequest, res: Response):
weather_forecast = {
"city": req.city,
"temperature": [],
"unit": "F",
"units": req.units,
}
for i in range(7):
min_temp = random.randrange(50,90)
max_temp = random.randrange(min_temp+5, min_temp+20)
if req.units.lower() == "celsius" or req.units.lower() == "c":
min_temp = (min_temp - 32) * 5.0/9.0
max_temp = (max_temp - 32) * 5.0/9.0
weather_forecast["temperature"].append({
"date": str(date.today() + timedelta(days=i)),
"temperature": {
"min": min_temp,
"max": max_temp
}
},
"units": req.units,
"query_time": str(datetime.now(timezone.utc))
})
return weather_forecast