fix(gismeteo): fix gismeteo parser
This commit is contained in:
@@ -38,6 +38,8 @@ def cloudness_icon(sky: Sky) -> list[str]:
|
|||||||
Cloudness.CLOUDY: "⛅",
|
Cloudness.CLOUDY: "⛅",
|
||||||
Cloudness.MAINLY_CLOUDY: "☁️",
|
Cloudness.MAINLY_CLOUDY: "☁️",
|
||||||
}[sky.cloudness]
|
}[sky.cloudness]
|
||||||
|
elif sky.precipitation in [Precipitation.SNOW, Precipitation.HEAVY_SNOW]:
|
||||||
|
main_icon = "🌨️"
|
||||||
else:
|
else:
|
||||||
main_icon = "🌧️"
|
main_icon = "🌧️"
|
||||||
icons = [main_icon]
|
icons = [main_icon]
|
||||||
|
|||||||
@@ -67,8 +67,17 @@ class SkyParser(RowParser[Sky]):
|
|||||||
PRECIPITATION_MAP: dict[str, Precipitation] = {
|
PRECIPITATION_MAP: dict[str, Precipitation] = {
|
||||||
"без осадков": Precipitation.NO,
|
"без осадков": Precipitation.NO,
|
||||||
"небольшой дождь": Precipitation.SMALL_RAIN,
|
"небольшой дождь": Precipitation.SMALL_RAIN,
|
||||||
|
"сильный дождь": Precipitation.HEAVY_RAIN,
|
||||||
"дождь": Precipitation.RAIN,
|
"дождь": Precipitation.RAIN,
|
||||||
"ливень": Precipitation.SHOWER,
|
"ливень": Precipitation.SHOWER,
|
||||||
|
"снег": Precipitation.SNOW,
|
||||||
|
"небольшой снег": Precipitation.SNOW,
|
||||||
|
"сильный снег": Precipitation.HEAVY_SNOW,
|
||||||
|
"мокрый снег": Precipitation.SNOW,
|
||||||
|
"снег с дождём": Precipitation.SNOW,
|
||||||
|
"сильный снег с дождём": Precipitation.HEAVY_SNOW,
|
||||||
|
"небольшой снег с дождём": Precipitation.SNOW,
|
||||||
|
"небольшой мокрый снег": Precipitation.SNOW,
|
||||||
}
|
}
|
||||||
|
|
||||||
def parse_row(self, tag: Tag) -> Iterable[Sky]:
|
def parse_row(self, tag: Tag) -> Iterable[Sky]:
|
||||||
@@ -112,7 +121,7 @@ class WindSpeedParser(RowParser[int]):
|
|||||||
|
|
||||||
def parse_row(self, tag: Tag) -> Iterable[int]:
|
def parse_row(self, tag: Tag) -> Iterable[int]:
|
||||||
for item in tag.select(
|
for item in tag.select(
|
||||||
".widget-row[data-row=wind-speed] > .row-item > speed-value"
|
".widget-row-wind > .row-item > .wind-speed > speed-value"
|
||||||
):
|
):
|
||||||
yield int(item.attrs["value"])
|
yield int(item.attrs["value"])
|
||||||
|
|
||||||
@@ -121,7 +130,7 @@ class WindGustParser(RowParser[int]):
|
|||||||
KEY = "wind_gust"
|
KEY = "wind_gust"
|
||||||
|
|
||||||
def parse_row(self, tag: Tag) -> Iterable[int]:
|
def parse_row(self, tag: Tag) -> Iterable[int]:
|
||||||
for item in tag.select(".widget-row[data-row=wind-gust] > .row-item"):
|
for item in tag.select(".widget-row-wind > .row-item > .wind-gust"):
|
||||||
value = item.select_one("speed-value")
|
value = item.select_one("speed-value")
|
||||||
yield int(value.attrs["value"]) if value else 0
|
yield int(value.attrs["value"]) if value else 0
|
||||||
|
|
||||||
@@ -130,6 +139,7 @@ class WindDirectionParser(RowParser[WindDirection]):
|
|||||||
KEY = "wind_direction"
|
KEY = "wind_direction"
|
||||||
|
|
||||||
WIND_DIRECTION_MAP: dict[str, WindDirection] = {
|
WIND_DIRECTION_MAP: dict[str, WindDirection] = {
|
||||||
|
"—": WindDirection.CALM,
|
||||||
"штиль": WindDirection.CALM,
|
"штиль": WindDirection.CALM,
|
||||||
"с": WindDirection.N,
|
"с": WindDirection.N,
|
||||||
"св": WindDirection.NE,
|
"св": WindDirection.NE,
|
||||||
@@ -143,15 +153,15 @@ class WindDirectionParser(RowParser[WindDirection]):
|
|||||||
|
|
||||||
def parse_row(self, tag: Tag) -> Iterable[float]:
|
def parse_row(self, tag: Tag) -> Iterable[float]:
|
||||||
for item in tag.select(
|
for item in tag.select(
|
||||||
".widget-row[data-row=wind-direction] > .row-item > .direction"
|
".widget-row-wind > .row-item > .wind-speed > .wind-direction"
|
||||||
):
|
):
|
||||||
wind_direction_str = item.text.lower()
|
wind_direction_str = item.text.lower().strip()
|
||||||
yield WindDirectionDeg.from_direction(
|
yield WindDirectionDeg.from_direction(
|
||||||
self.WIND_DIRECTION_MAP[wind_direction_str]
|
self.WIND_DIRECTION_MAP[wind_direction_str]
|
||||||
).value
|
).value
|
||||||
|
|
||||||
|
|
||||||
class WindPrecipitationParser(RowParser[float]):
|
class PrecipitationParser(RowParser[float]):
|
||||||
KEY = "precipitation"
|
KEY = "precipitation"
|
||||||
|
|
||||||
def parse_row(self, tag: Tag) -> Iterable[float]:
|
def parse_row(self, tag: Tag) -> Iterable[float]:
|
||||||
@@ -175,7 +185,9 @@ class HumidityParser(RowParser[int]):
|
|||||||
KEY = "humidity"
|
KEY = "humidity"
|
||||||
|
|
||||||
def parse_row(self, tag: Tag) -> Iterable[int]:
|
def parse_row(self, tag: Tag) -> Iterable[int]:
|
||||||
for item in tag.select(".widget-row[data-row=humidity] > .row-item"):
|
for item in tag.select(
|
||||||
|
".widget-row[data-row=humidity] > .row-item, .widget-row[data-row=humidity-avg] > .row-item"
|
||||||
|
):
|
||||||
yield int(item.text)
|
yield int(item.text)
|
||||||
|
|
||||||
|
|
||||||
@@ -186,7 +198,7 @@ ROW_PARSERS: list[RowParser] = [
|
|||||||
WindSpeedParser(),
|
WindSpeedParser(),
|
||||||
WindGustParser(),
|
WindGustParser(),
|
||||||
WindDirectionParser(),
|
WindDirectionParser(),
|
||||||
WindPrecipitationParser(),
|
PrecipitationParser(),
|
||||||
PressureParser(),
|
PressureParser(),
|
||||||
HumidityParser(),
|
HumidityParser(),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ class Precipitation(str, Enum):
|
|||||||
NO = "no"
|
NO = "no"
|
||||||
SMALL_RAIN = "small_rain"
|
SMALL_RAIN = "small_rain"
|
||||||
RAIN = "rain"
|
RAIN = "rain"
|
||||||
|
HEAVY_RAIN = "heavy_rain"
|
||||||
SHOWER = "shower"
|
SHOWER = "shower"
|
||||||
|
SNOW = "snow"
|
||||||
|
HEAVY_SNOW = "heavy_snow"
|
||||||
|
|
||||||
|
|
||||||
class Sky(Model):
|
class Sky(Model):
|
||||||
|
|||||||
Reference in New Issue
Block a user