- Создать utils/pogoda.py с общими функциями: - fetch_weather, fetch_open_meteo, wmo_to_russian, translate_weather, pressure_to_mmhg - Обновить commands/pogoda.py: убрать дубликаты, импортировать из utils - Обновить console_commands/pogoda.py: убрать дубликаты, импортировать из utils - Сделать console_commands/pogoda.py async (требует fetch_weather) - Обновить AGENTS.md и ISSUES.md (проблема 7 решена)
35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
from utils.pogoda import fetch_weather, fetch_open_meteo, wmo_to_russian, translate_weather, pressure_to_mmhg
|
||
|
||
|
||
async def pogoda(stop_event, bot):
|
||
"""Вывести прогноз погоды для Магнитогорска"""
|
||
api_url = "https://wttr.in/Magnitogorsk?format=j1&lang=ru"
|
||
data = await fetch_weather(api_url)
|
||
|
||
if data is None:
|
||
print("Не удалось получить данные о погоде.")
|
||
return
|
||
|
||
current = data.get("current_condition", [{}])[0]
|
||
if not current:
|
||
print("Не удалось получить данные о погоде.")
|
||
return
|
||
|
||
temp = current.get("temp_C", "—")
|
||
feels_like = current.get("FeelsLikeC", "—")
|
||
description = translate_weather(current.get("weatherDesc", [{}])[0].get("value", "—"))
|
||
humidity = current.get("humidity", "—")
|
||
wind_kmh = current.get("windspeedKmph", "—")
|
||
try:
|
||
wind = round(int(wind_kmh) / 3.6, 1) if wind_kmh != "—" else "—"
|
||
except (ValueError, TypeError):
|
||
wind = "—"
|
||
pressure_mb = current.get("pressure", "—")
|
||
pressure_mm = pressure_to_mmhg(pressure_mb)
|
||
|
||
print(f"[TEMP] Температура: {temp}°C (ощущается как {feels_like}°C)")
|
||
print(f"[DESC] Описание: {description}")
|
||
print(f"[HUMID] Влажность: {humidity}%")
|
||
print(f"[WIND] Ветер: {wind} м/с")
|
||
print(f"[PRESS] Давление: {pressure_mm} мм рт. ст.")
|