refactor(weather): add wind object to WeatherValue model

This commit is contained in:
2026-09-15 18:00:22 +03:00
parent 91a1e4498c
commit d47dcf69e6
10 changed files with 83 additions and 94 deletions
+11 -2
View File
@@ -28,6 +28,15 @@ def format_date(date: datetime.date) -> str:
return f"{days + 1}-day"
def set_dict_nested_value(target: dict, key: str, value: Any):
parts = key.split(".")
for part in parts[:-1]:
if part not in target:
target[part] = {}
target = target[part]
target[parts[-1]] = value
class GismeteoApi(WeatherApi):
PROVIDER = "gismeteo"
@@ -46,7 +55,7 @@ class GismeteoApi(WeatherApi):
for index, value in enumerate(parser.parse_row(widget)):
while len(result) < index + 1:
result.append({})
result[index][parser.KEY] = value
set_dict_nested_value(result[index], parser.KEY, value)
values = [WeatherValue(**item) for item in result]
# group values by 3 hours
if len(values) > 8:
@@ -70,7 +79,7 @@ class GismeteoApi(WeatherApi):
for index, value in enumerate(parser.parse_row(widget)):
while len(result) < index + 1:
result.append({})
result[index][parser.KEY] = value
set_dict_nested_value(result[index], parser.KEY, value)
values = [WeatherValue(**item) for item in result]
return WeatherResponse(
location=location or "n/a",