import logging from discord.ext import commands from utils.pogoda import API_URL_WEATHER, fetch_weather, format_weather_data_for_console logger = logging.getLogger(__name__) class Pg(commands.Cog): """Команда !pg — прогноз погоды для Магнитогорска""" def __init__(self): self.api_url = API_URL_WEATHER @commands.command(name="pg") async def pg(self, ctx): """Прогноз погоды в Магнитогорске""" data = await fetch_weather(self.api_url) if data is None: logger.warning("%s: !pg — не удалось получить погоду (API вернул None)", ctx.author) await ctx.send("Не удалось получить данные о погоде.") return formatted = format_weather_data_for_console(data) if not formatted: logger.warning("%s: !pg — данные погоды пустые", ctx.author) await ctx.send("Не удалось получить данные о погоде.") return await ctx.send("\n".join(formatted)) logger.info("%s: !pg выполнена", ctx.author)