feat(weather): wehaer value sky model instead of text cloudness
This commit is contained in:
@@ -1,21 +1,60 @@
|
||||
import datetime
|
||||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class WeatherValue(BaseModel):
|
||||
class Model(BaseModel):
|
||||
class Config:
|
||||
use_enum_values = True
|
||||
|
||||
|
||||
class Cloudness(str, Enum):
|
||||
CLEAR = "clear"
|
||||
PARTLY_CLOUDY = "party_cloudy"
|
||||
CLOUDY = "cloudy"
|
||||
MAINLY_CLOUDY = "mainly_cloudy"
|
||||
|
||||
|
||||
class Precipitation(str, Enum):
|
||||
NO = "no"
|
||||
SMALL_RAIN = "small_rain"
|
||||
RAIN = "rain"
|
||||
SHOWER = "shower"
|
||||
|
||||
|
||||
class Sky(Model):
|
||||
cloudness: Cloudness
|
||||
precipitation: Precipitation
|
||||
thunder: bool
|
||||
fog: bool
|
||||
|
||||
|
||||
class WindDirection(str, Enum):
|
||||
CALM = "calm"
|
||||
N = "N"
|
||||
NO = "NO"
|
||||
O = "O"
|
||||
SO = "SO"
|
||||
S = "S"
|
||||
SW = "SW"
|
||||
W = "W"
|
||||
NW = "NW"
|
||||
|
||||
|
||||
class WeatherValue(Model):
|
||||
date: datetime.datetime
|
||||
cloudness: str
|
||||
sky: Sky
|
||||
temperature: int
|
||||
wind_speed: int
|
||||
wind_gust: int
|
||||
wind_direction: str
|
||||
wind_direction: WindDirection
|
||||
precipitation: float
|
||||
pressure: int
|
||||
humidity: int
|
||||
|
||||
|
||||
class WeatherResponse(BaseModel):
|
||||
class WeatherResponse(Model):
|
||||
location: str
|
||||
date: datetime.date
|
||||
period: str
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
def wind_direction_icon(wind_direction: str) -> str:
|
||||
from weather.model import Cloudness, Precipitation, Sky, WindDirection
|
||||
|
||||
|
||||
def wind_direction_icon(wind_direction: WindDirection) -> str:
|
||||
return {
|
||||
"С": "🡫",
|
||||
"СВ": "🡯",
|
||||
"В": "🡨",
|
||||
"ЮВ": "🡬",
|
||||
"Ю": "🡡",
|
||||
"ЮЗ": "🡭",
|
||||
"З": "🡪",
|
||||
"СЗ": "🡦",
|
||||
"штиль": "",
|
||||
WindDirection.N: "🡫",
|
||||
WindDirection.NO: "🡯",
|
||||
WindDirection.O: "🡨",
|
||||
WindDirection.SO: "🡬",
|
||||
WindDirection.S: "🡡",
|
||||
WindDirection.SW: "🡭",
|
||||
WindDirection.W: "🡪",
|
||||
WindDirection.NW: "🡦",
|
||||
WindDirection.CALM: "",
|
||||
}.get(wind_direction, wind_direction)
|
||||
|
||||
|
||||
def cloudness_icon(cloudness: str) -> list[str]:
|
||||
icons = []
|
||||
values = {item.strip().lower() for item in cloudness.split(",")}
|
||||
if "дымка" in values:
|
||||
def cloudness_icon(sky: Sky) -> list[str]:
|
||||
main_icon = ""
|
||||
if sky.thunder:
|
||||
if sky.cloudness == Cloudness.CLEAR:
|
||||
main_icon = "🌩️"
|
||||
if sky.precipitation == Precipitation.NO:
|
||||
main_icon = "⚡"
|
||||
else:
|
||||
main_icon = "⛈️"
|
||||
elif sky.precipitation == Precipitation.NO:
|
||||
main_icon = {
|
||||
Cloudness.CLEAR: "☀️",
|
||||
Cloudness.PARTLY_CLOUDY: "🌤️",
|
||||
Cloudness.CLOUDY: "⛅",
|
||||
Cloudness.MAINLY_CLOUDY: "☁️",
|
||||
}[sky.cloudness]
|
||||
else:
|
||||
main_icon = "🌧️"
|
||||
icons = [main_icon]
|
||||
if sky.fog:
|
||||
icons.append("🌫️")
|
||||
values.remove("дымка")
|
||||
icons = [
|
||||
{
|
||||
frozenset(["ясно"]): "☀️",
|
||||
frozenset(["малооблачно", "без осадков"]): "🌤️",
|
||||
frozenset(["облачно", "без осадков"]): "⛅",
|
||||
frozenset(["малооблачно", "небольшой дождь"]): "🌦️",
|
||||
frozenset(["пасмурно", "без осадков"]): "☁️",
|
||||
frozenset(["облачно", "небольшой дождь"]): "🌧️",
|
||||
frozenset(["облачно", "дождь"]): "🌧️",
|
||||
frozenset(["облачно", "небольшой дождь", "гроза"]): "⛈️",
|
||||
frozenset(["малооблачно", "дождь"]): "🌦️",
|
||||
frozenset(["пасмурно", "небольшой дождь"]): "🌧️",
|
||||
frozenset(["облачно", "дождь", "гроза"]): "⛈️",
|
||||
frozenset(["пасмурно", "дождь"]): "🌧️",
|
||||
frozenset(["пасмурно", "дождь", "гроза"]): "⛈️",
|
||||
}.get(frozenset(values), "|".join(values))
|
||||
] + icons
|
||||
return icons
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<tr>
|
||||
{% for value in response.values %}
|
||||
<td class="cloudness">
|
||||
{% for icon in value.cloudness | cloudness_icon %}
|
||||
{% for icon in value.sky | cloudness_icon %}
|
||||
<div class="icon">{{icon}}</div>
|
||||
{% endfor %}
|
||||
</td>
|
||||
@@ -76,7 +76,6 @@
|
||||
{% for value in response.values %}
|
||||
<td class="wind">
|
||||
<span class="icon">{{value.wind_direction | wind_direction_icon}}</span>
|
||||
<span class="direction">{{value.wind_direction}}</span>
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user