92 lines
1.7 KiB
Python
92 lines
1.7 KiB
Python
import datetime
|
|
from enum import StrEnum, auto
|
|
from typing import Literal, Self
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class Model(BaseModel):
|
|
class Config:
|
|
use_enum_values = True
|
|
|
|
|
|
class Location(Model):
|
|
id: str
|
|
name: str
|
|
provider: str
|
|
lat: float
|
|
lon: float
|
|
country: str
|
|
country_code: str
|
|
district: str
|
|
subdistrict: str
|
|
|
|
|
|
class Cloudness(StrEnum):
|
|
CLEAR = auto()
|
|
PARTLY_CLOUDY = auto()
|
|
CLOUDY = auto()
|
|
MAINLY_CLOUDY = auto()
|
|
|
|
values: list[Self]
|
|
|
|
|
|
Cloudness.values = list(Cloudness)
|
|
|
|
|
|
class Precipitation(StrEnum):
|
|
NO = auto()
|
|
SMALL_RAIN = auto()
|
|
RAIN = auto()
|
|
HEAVY_RAIN = auto()
|
|
SHOWER = auto()
|
|
SNOW = auto()
|
|
HEAVY_SNOW = auto()
|
|
HAIL = auto()
|
|
|
|
values: list[Self]
|
|
|
|
|
|
Precipitation.values = list(Precipitation)
|
|
|
|
|
|
class Sky(Model):
|
|
cloudness: Cloudness = Cloudness.CLEAR
|
|
precipitation: Precipitation = Precipitation.NO
|
|
thunder: bool = False
|
|
fog: bool = False
|
|
|
|
|
|
class WindDirection(StrEnum):
|
|
N = auto()
|
|
NE = auto()
|
|
E = auto()
|
|
SE = auto()
|
|
S = auto()
|
|
SW = auto()
|
|
W = auto()
|
|
NW = auto()
|
|
|
|
|
|
class Wind(Model):
|
|
speed: int = 0
|
|
gust: int = 0
|
|
direction: WindDirection | None = None
|
|
|
|
|
|
class WeatherValue(Model):
|
|
date: datetime.datetime
|
|
sky: Sky = Field(default_factory=Sky)
|
|
wind: Wind = Field(default_factory=Wind)
|
|
temperature: list[int] = Field(default_factory=list)
|
|
precipitation: float = 0
|
|
pressure: list[int] = Field(default_factory=list)
|
|
humidity: int = -1
|
|
|
|
|
|
class WeatherResponse(Model):
|
|
location: str
|
|
date: datetime.date
|
|
period: Literal["day", "days"] = "day"
|
|
values: list[WeatherValue]
|