import discord from discord.ext import commands from utils.pogoda import fetch_weather, fetch_open_meteo, wmo_to_russian, translate_weather, pressure_to_mmhg class Pogoda(commands.Cog): """Команда !pogoda — прогноз погоды для Магнитогорска""" def __init__(self): self.api_url = "https://wttr.in/Magnitogorsk?format=j1&lang=ru" @commands.command(name="pogoda") async def pogoda(self, ctx): data = await fetch_weather(self.api_url) if data is None: return current = data.get("current_condition", [{}])[0] if not current: await ctx.send("Не удалось получить данные о погоде.") 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) await ctx.send( f"Температура: {temp}°C (ощущается как {feels_like}°C)\n" f"Описание: {description}\n" f"Влажность: {humidity}%\n" f"Ветер: {wind} м/с\n" f"Давление: {pressure_mm} мм рт. ст." )