from .. import loader, utils
import aiohttp
@loader.tds
class WeatherMod(loader.Module):
"""Модуль для просмотра погоды"""
strings = {
"name": "K:Weather",
"no_city": "❌ Укажите город!",
"error": "❌ Ошибка получения погоды.",
"weather": "⚡️ Погода в {}\n\n"
"🌎 Состояние: {}\n"
"🔥 Температура: {}°C\n"
"🌈 Ветер: {} км/ч\n"
"🌨 Влажность: {}%"
}
async def weathercmd(self, message):
"""Использование: .weather <город>"""
args = utils.get_args_raw(message)
if not args:
await utils.answer(message, self.strings["no_city"])
return
async with aiohttp.ClientSession() as session:
try:
async with session.get(f"https://wttr.in/{args}?format=j1&lang=ru") as response:
if response.status != 200:
await utils.answer(message, self.strings["error"])
return
weather_data = await response.json()
current = weather_data["current_condition"][0]
await utils.answer(
message,
self.strings["weather"].format(
args,
current["lang_ru"][0]["value"],
current["temp_C"],
current["windspeedKmph"],
current["humidity"]
)
)
except Exception:
await utils.answer(message, self.strings["error"])