Fix command detection and improve weather timing

This commit is contained in:
2026-02-02 23:30:57 +03:00
parent 845ef7c531
commit a61f526ce4
5 changed files with 38 additions and 18 deletions

View File

@@ -427,13 +427,18 @@ def get_weather_report(requested_city: str = None) -> str:
report += f" Сегодня температура будет от {get_temperature_text(t_min)} до {get_temperature_text(t_max)}."
# --- 3. Forecast Next 4 Hours ---
current_hour = datetime.now().hour
hourly_temps = data["hourly"]["temperature_2m"]
hourly_precip = data["hourly"]["precipitation"]
hourly_codes = data["hourly"]["weather_code"]
hourly_times = data["hourly"].get("time", [])
# Start from next hour
start_idx = current_hour + 1
# Start from the next hour based on the API's current time (timezone-aware for the location).
current_time_iso = data.get("current", {}).get("time")
if current_time_iso and current_time_iso in hourly_times:
start_idx = hourly_times.index(current_time_iso) + 1
else:
current_hour = datetime.now().hour
start_idx = current_hour + 1
end_idx = min(start_idx + 4, len(hourly_temps))
next_temps = hourly_temps[start_idx:end_idx]
@@ -484,4 +489,4 @@ def get_weather_report(requested_city: str = None) -> str:
return f"Получены некорректные данные о погоде."
except Exception as e:
print(f"❌ Ошибка получения погоды: {e}")
return "Не удалось получить полные данные о погоде."
return "Не удалось получить полные данные о погоде."