feat(api): add multiple days api
This commit is contained in:
@@ -9,6 +9,7 @@ from fastapi.templating import Jinja2Templates
|
||||
from gismeteo import datehelp
|
||||
from gismeteo.location import LOCATION_BUNDLE
|
||||
from gismeteo.mock import MOCK_DATA
|
||||
from weather.api import WeatherApi
|
||||
from weather.model import WeatherResponse
|
||||
|
||||
from .filters import cloudness_icon, wind_direction_icon
|
||||
@@ -47,20 +48,26 @@ def mount(app: FastAPI):
|
||||
|
||||
@app.get("/weather/{location}", response_class=RedirectResponse)
|
||||
async def get_weather_default(location: str):
|
||||
return RedirectResponse(f"{location}/{datetime.date.today()}")
|
||||
return RedirectResponse(f"{location}/day/{datetime.date.today()}")
|
||||
|
||||
@app.get("/weather/{location}/mock", response_class=HTMLResponse)
|
||||
async def get_weather_mock(request: Request):
|
||||
response = MOCK_DATA.response
|
||||
@app.get("/weather/{location}/day/mock", response_class=HTMLResponse)
|
||||
async def get_weather_day_mock(request: Request):
|
||||
response = MOCK_DATA.get_response("day")
|
||||
return build_weather_response(request, response)
|
||||
|
||||
# @app.get("/weather/{location}/{day}", response_class=HTMLResponse)
|
||||
async def get_weather_day(request: Request, location: str, day: datehelp.Day):
|
||||
date = datehelp.parse(day)
|
||||
response = await request.app.state.weather_api.get_day(location, date)
|
||||
@app.get("/weather/{location}/days/mock", response_class=HTMLResponse)
|
||||
async def get_weather_days_mock(request: Request):
|
||||
response = MOCK_DATA.get_response("days")
|
||||
return build_weather_response(request, response)
|
||||
|
||||
@app.get("/weather/{location}/{date}", response_class=HTMLResponse)
|
||||
async def get_weather(request: Request, location: str, date: datetime.date):
|
||||
response = await request.app.state.weather_api.get_day(location, date)
|
||||
@app.get("/weather/{location}/day/{date}", response_class=HTMLResponse)
|
||||
async def get_weather_day(request: Request, location: str, date: datetime.date):
|
||||
weather_api: WeatherApi = request.app.state.weather_api
|
||||
response = await weather_api.get_day(location, date)
|
||||
return build_weather_response(request, response)
|
||||
|
||||
@app.get("/weather/{location}/days/{days}", response_class=HTMLResponse)
|
||||
async def get_weather_days(request: Request, location: str, days: int):
|
||||
weather_api: WeatherApi = request.app.state.weather_api
|
||||
response = await weather_api.get_days(location, days)
|
||||
return build_weather_response(request, response)
|
||||
|
||||
Reference in New Issue
Block a user