This repository has been archived on 2026-04-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
n8n-helper/src/routes/weather.py
T

27 lines
921 B
Python

from fastapi import APIRouter
from httpx import AsyncClient
from lib.exceptions import FetchException, ParseException
from models.weather import Weather
from lib import logger
router = APIRouter(prefix="/weather", tags=["Weather"])
@router.get("/")
async def weather():
url = "https://www.ilmatieteenlaitos.fi/api/weather/observations?fmisid=101237&observations=true&radar=false&daily=false"
async with AsyncClient() as client:
response = await client.get(url)
if response.status_code != 200:
raise FetchException(response.url, response.status_code)
data = response.json()
if not data:
raise FetchException(response.url, response.status_code)
try:
weather = [Weather(**d) for d in data["observations"] if d["t2m"] is not None]
except Exception as e:
logger.error(f"Error parsing weather: {str(e)}")
raise ParseException()
return weather