30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
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 — прогноз погоды для Магнитогорска"""
|
||
|
||
@commands.command(name="pg")
|
||
async def pg(self, ctx: commands.Context) -> None:
|
||
"""Прогноз погоды в Магнитогорске"""
|
||
data = await fetch_weather(API_URL_WEATHER)
|
||
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)
|