30 lines
815 B
Python
30 lines
815 B
Python
from typing import Self
|
||
|
||
from gallery.sketch.weather.model import WindDirection, WindDirectionDeg
|
||
|
||
|
||
class ParseError(Exception):
|
||
@classmethod
|
||
def invalid_date(cls, date_str: str) -> Self:
|
||
return cls("Invalid date string", date_str)
|
||
|
||
|
||
WIND_DIRECTION_MAP: dict[str, WindDirection] = {
|
||
"—": WindDirection.CALM,
|
||
"": WindDirection.CALM,
|
||
"штиль": WindDirection.CALM,
|
||
"штл": WindDirection.CALM,
|
||
"с": WindDirection.N,
|
||
"св": WindDirection.NE,
|
||
"в": WindDirection.E,
|
||
"юв": WindDirection.SE,
|
||
"ю": WindDirection.S,
|
||
"юз": WindDirection.SW,
|
||
"з": WindDirection.W,
|
||
"сз": WindDirection.NW,
|
||
}
|
||
|
||
|
||
def parse_wind_direction(value: str) -> WindDirectionDeg:
|
||
return WindDirectionDeg.from_direction(WIND_DIRECTION_MAP[value.replace("-", "").lower()])
|