refactor(weather): add wind object to WeatherValue model
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user